Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl rand_core::RngCore & support all integers in Rng #284

Merged
merged 4 commits into from
Dec 5, 2021

Conversation

olback
Copy link
Member

@olback olback commented Dec 2, 2021

No description provided.

@olback olback marked this pull request as draft December 2, 2021 03:55
src/rng.rs Show resolved Hide resolved
fn fill(&mut self, dest: &mut [$type]) -> Result<(), ErrorKind> {
let len = dest.len() * (mem::size_of::<$type>() / mem::size_of::<u32>());
let ptr = dest.as_mut_ptr() as *mut u32;
let slice_u32 = unsafe { core::slice::from_raw_parts_mut(ptr, len) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is alignment an issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mem::align_of::<u32>() = 4
mem::align_of::<u64>() = 8
mem::align_of::<u128>() = 8

I don't think so. u64/u128 is 8-byte aligned which would be valid for 4-byte aligned values as well. https://doc.rust-lang.org/reference/type-layout.html#size-and-alignment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I hadn't seen the distinction between rng_core and rng_core_large.

src/rng.rs Outdated Show resolved Hide resolved
@olback olback marked this pull request as ready for review December 2, 2021 06:01
Copy link
Member

@richardeoin richardeoin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks @olback, and also @AlyoshaVasilieva @mattico for the reviews 🎉

src/rng.rs Outdated Show resolved Hide resolved
@olback olback requested a review from richardeoin December 5, 2021 05:30
Copy link
Member

@richardeoin richardeoin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

@bors bors bot merged commit d3ff76d into stm32-rs:master Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants