Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed Mar 29, 2021
1 parent 23c6602 commit 6cfe768
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/lib.rs
Expand Up @@ -571,6 +571,8 @@ macro_rules! arbitrary_tuple {
}
arbitrary_tuple!(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);

// Helper to safely create arrays since the standard library doesn't
// provide one yet. Shouldn't be necessary in the future.
struct ArrayGuard<T, const N: usize> {
dst: *mut T,
initialized: usize,
Expand All @@ -591,10 +593,9 @@ where
F: FnMut(usize) -> T,
{
let mut array: mem::MaybeUninit<[T; N]> = mem::MaybeUninit::uninit();
let mut guard: ArrayGuard<T, N> = ArrayGuard {
dst: array.as_mut_ptr() as _,
initialized: 0,
};
let array_ptr = array.as_mut_ptr();
let dst = array_ptr as _;
let mut guard: ArrayGuard<T, N> = ArrayGuard { dst, initialized: 0 };
unsafe {
for (idx, value_ptr) in (&mut *array.as_mut_ptr()).iter_mut().enumerate() {
core::ptr::write(value_ptr, cb(idx));
Expand All @@ -610,10 +611,9 @@ where
F: FnMut(usize) -> Result<T>,
{
let mut array: mem::MaybeUninit<[T; N]> = mem::MaybeUninit::uninit();
let mut guard: ArrayGuard<T, N> = ArrayGuard {
dst: array.as_mut_ptr() as _,
initialized: 0,
};
let array_ptr = array.as_mut_ptr();
let dst = array_ptr as _;
let mut guard: ArrayGuard<T, N> = ArrayGuard { dst, initialized: 0 };
unsafe {
for (idx, value_ptr) in (&mut *array.as_mut_ptr()).iter_mut().enumerate() {
core::ptr::write(value_ptr, cb(idx)?);
Expand Down

0 comments on commit 6cfe768

Please sign in to comment.