diff --git a/package/origlang-slice-in-box/src/lib.rs b/package/origlang-slice-in-box/src/lib.rs index 82d7036..db5a6ba 100644 --- a/package/origlang-slice-in-box/src/lib.rs +++ b/package/origlang-slice-in-box/src/lib.rs @@ -9,7 +9,7 @@ pub fn create_initialized_boxed_slice(len: usize, mut create_element: impl Fn e.write(create_element(i)); } - unsafe { assume_every_elements_are_initialized(slice) } + unsafe { slice.assume_init() } } pub fn try_create_initialized_boxed_slice(len: usize, mut try_create_element: impl FnMut(usize) -> Result) -> Result, E> { @@ -18,13 +18,5 @@ pub fn try_create_initialized_boxed_slice(len: usize, mut try_create_eleme e.write(try_create_element(i)?); } - Ok(unsafe { assume_every_elements_are_initialized(slice) }) -} - -unsafe fn assume_every_elements_are_initialized(half_baked_slice_in_box: BoxedSlice>) -> BoxedSlice { - let ptr = Box::into_raw(half_baked_slice_in_box); - // SAFETY: caller must initialize elements in the fed MaybeUninit-slice. - let slice = ptr as *mut [I]; - - unsafe { Box::from_raw(slice) } + Ok(unsafe { slice.assume_init() }) }