MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/splashsurf / new

Method new

splashsurf_lib/src/utils.rs:34–43  ·  view source on GitHub ↗

Wraps a slice to be able to share mutable access between threads

(slice: &'a mut [T])

Source from the content-addressed store, hash-verified

32impl<'a, T> UnsafeSlice<'a, T> {
33 /// Wraps a slice to be able to share mutable access between threads
34 pub fn new(slice: &'a mut [T]) -> Self {
35 // SAFETY: `&mut` ensures unique access.
36 // See `Cell::from_mut`: https://doc.rust-lang.org/std/cell/struct.Cell.html#method.from_mut
37 // SAFETY: `UnsafeCell<T>` has the same memory layout as `T`.
38 // See `Cell::as_slice_of_cells`: https://doc.rust-lang.org/std/cell/struct.Cell.html#method.as_slice_of_cells
39 let ptr = slice as *mut [T] as *const [UnsafeCell<T>];
40 Self {
41 slice: unsafe { &*ptr },
42 }
43 }
44
45 /// Returns the length of the wrapped slice
46 pub fn len(&self) -> usize {

Callers

nothing calls this directly

Calls 1

maxMethod · 0.45

Tested by

no test coverage detected