Skip to main content

FromBytes

Trait FromBytes 

Source
pub unsafe trait FromBytes: Copy + 'static {
    // Provided method
    fn from_bytes(bytes: &[u8]) -> Result<&Self>
       where Self: Sized { ... }
}
Expand description

Allows for reading plain data structures from a u8 slice

§Safety

This trait and its operations are only safe for structures which are purely composed of plain data and have a C-style memory layout aka. #[repr(C)]

Provided Methods§

Source

fn from_bytes(bytes: &[u8]) -> Result<&Self>
where Self: Sized,

Returns a reference to a single instance of Self represented by the specified bytes. Does not check for correct endianness.

§Errors

This function will return an error if:

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl FromBytes for u8

Source§

impl FromBytes for u16

Source§

impl FromBytes for u32

Source§

impl FromBytes for u64

Implementors§