Wraps a slice to be able to share mutable access between threads
(slice: &'a mut [T])
| 32 | impl<'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 { |