MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / from

Method from

crates/data-structures/src/slim_slice.rs:371–387  ·  view source on GitHub ↗
(slice: SlimSliceBox<T>)

Source from the content-addressed store, hash-verified

369 impl<T> From<SlimSliceBox<T>> for Box<[T]> {
370 #[inline]
371 fn from(slice: SlimSliceBox<T>) -> Self {
372 let slice = ManuallyDrop::new(slice);
373 let (ptr, len) = slice.raw.split();
374 // SAFETY: All paths to creating a `SlimSliceBox`
375 // go through `SlimSliceBox::from_boxed_unchecked`
376 // which requires a valid `Box<[T]>`.
377 // The function also uses `Box::into_raw`
378 // and the original length is kept.
379 //
380 // It therefore follows that if we reuse the same
381 // pointer and length as given to us by a valid `Box<[T]>`,
382 // we can use `Box::from_raw` to reconstruct the `Box<[T]>`.
383 //
384 // We also no longer claim ownership of the data pointed to by `ptr`
385 // by virtue of `ManuallyDrop` preventing `Drop for SlimSliceBox<T>`.
386 unsafe { Box::from_raw(slice_from_raw_parts_mut(ptr, len)) }
387 }
388 }
389}
390

Callers

nothing calls this directly

Calls 5

into_boxFunction · 0.85
splitMethod · 0.80
newFunction · 0.70
into_innerMethod · 0.45
derefMethod · 0.45

Tested by

no test coverage detected