[][src]Function cast_rs::slicecast::cast

pub unsafe fn cast<T, U>(e: &[T]) -> &[U]

Performs a cast between two immutable slice types.

This is unsafe because there is no guarantee that the resulting slice contains valid data.

The underlying buffer of the given slice must begin at a non-null address, even if the slice itself has a length of zero.

Panics

This function panics if the resulting slice cannot hold the same number of bytes as the original slice.

Example

let foo: [u8; 4] = [1, 0, 0, 0];
let bar: &[u32] = unsafe { slice_cast::cast(&foo) };
println!("{:?}", bar);