MCPcopy Create free account
hub / github.com/RustCrypto/utils / cast_slice_mut

Function cast_slice_mut

cmov/src/slice.rs:331–344  ·  view source on GitHub ↗

Performs an unsafe pointer cast from one mutable slice type to the other. # Compile-time panics - If `T` and `U` differ in size - If `T` and `U` differ in alignment

(slice: &mut [T])

Source from the content-addressed store, hash-verified

329/// - If `T` and `U` differ in size
330/// - If `T` and `U` differ in alignment
331unsafe fn cast_slice_mut<T, U>(slice: &mut [T]) -> &mut [U] {
332 const {
333 assert!(size_of::<T>() == size_of::<U>(), "T/U size differs");
334 assert!(align_of::<T>() == align_of::<U>(), "T/U alignment differs");
335 }
336
337 // SAFETY:
338 // - Slices are of same-sized/aligned types as asserted above.
339 // - It's up to the caller to ensure the pointer cast from `T` to `U` itself is valid.
340 #[allow(unsafe_code)]
341 unsafe {
342 &mut *(ptr::from_mut::<[T]>(slice) as *mut [U])
343 }
344}
345
346/// Compare the two remainder slices by loading a `Word` then performing `cmovne`.
347#[inline]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected