Skip to content

Commit

Permalink
Merge pull request #640 from KisaragiEffective/replace-string-with-bo…
Browse files Browse the repository at this point in the history
…xed-str
  • Loading branch information
KisaragiEffective authored Dec 8, 2024
2 parents 09e93cb + 840454e commit 8ad70fe
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions package/origlang-slice-in-box/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn create_initialized_boxed_slice<I>(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<I, E>(len: usize, mut try_create_element: impl FnMut(usize) -> Result<I, E>) -> Result<BoxedSlice<I>, E> {
Expand All @@ -18,13 +18,5 @@ pub fn try_create_initialized_boxed_slice<I, E>(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<I>(half_baked_slice_in_box: BoxedSlice<MaybeUninit<I>>) -> BoxedSlice<I> {
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() })
}

0 comments on commit 8ad70fe

Please sign in to comment.