Function safe_transmute::base::from_bytes[][src]

pub unsafe fn from_bytes<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 at least enough bytes to fill a single instance of a type, extraneous data is ignored.

Safety

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

Errors

An error is returned if the slice does not have enough bytes for a single value T.

Examples

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