Trait as_with_bytes::WithBytes
[−]
[src]
pub trait WithBytes { unsafe fn with_bytes<'a>(bytes: &'a [u8]) -> &'a Self; }
A trait used for converting from bytes.
Required Methods
unsafe fn with_bytes<'a>(bytes: &'a [u8]) -> &'a Self
Returns a Self
representation of the given slice of bytes.
Unsafe
This function is unsafe for two reasons: Firstly, If the
length of bytes
is shorter than size_of::<Self>
,
arbitrary memory is read. Secondly, invalid values can
be returned, such as an instance of an empty enum.
This method will work fine as long as you are careful to
avoid both scenarios.