Performs an unsafe pointer cast from one slice type to the other. # Compile-time panics - If `T` and `U` differ in size - If `T` and `U` differ in alignment
(slice: &[T])
| 309 | /// - If `T` and `U` differ in size |
| 310 | /// - If `T` and `U` differ in alignment |
| 311 | unsafe fn cast_slice<T, U>(slice: &[T]) -> &[U] { |
| 312 | const { |
| 313 | assert!(size_of::<T>() == size_of::<U>(), "T/U size differs"); |
| 314 | assert!(align_of::<T>() == align_of::<U>(), "T/U alignment differs"); |
| 315 | } |
| 316 | |
| 317 | // SAFETY: |
| 318 | // - Slices are of same-sized/aligned types as asserted above. |
| 319 | // - It's up to the caller to ensure the pointer cast from `T` to `U` itself is valid. |
| 320 | #[allow(unsafe_code)] |
| 321 | unsafe { |
| 322 | &*(ptr::from_ref::<[T]>(slice) as *const [U]) |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | /// Performs an unsafe pointer cast from one mutable slice type to the other. |
| 327 | /// |
nothing calls this directly
no outgoing calls
no test coverage detected