-
Notifications
You must be signed in to change notification settings - Fork 105
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
Conversation
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) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is alignment an issue?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this 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 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors r+
No description provided.