Function safe_transmute::base::from_bytes_pedantic[][src]

pub unsafe fn from_bytes_pedantic<T: Copy>(
    bytes: &[u8]
) -> Result<T, Error<'_, u8, T>>

Convert a byte slice into a single instance of a Copyable type.

The byte slice must have exactly the expected number of bytes to fill a single instance of a type, without trailing space.

Safety

Failure to fulfill any of the requirements above may result in undefined behavior.

Errors

An error is returned if the slice’s length is not equal to the size of a single value T.

Examples

// Little-endian
unsafe {
    assert_eq!(from_bytes_pedantic::<u32>(&[0x00, 0x00, 0x00, 0x01])?, 0x0100_0000);
}