Trait zerovec::ule::VarULE [−][src]
pub trait VarULE: 'static { type Error; fn parse_byte_slice(bytes: &[u8]) -> Result<&Self, Self::Error>; unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &Self; fn as_byte_slice(&self) -> &[u8]; }
Expand description
Variable-width, byte-aligned data that can be cast to and from a little-endian byte slice.
This trait is mostly for unsized types like str
and [T]
. It can be implemented on sized types,
however it is much more preferable to use ULE
for that purpose.
Associated Types
The error type to used by VarULE::parse_byte_slice()
Required methods
Parses a byte slice, &[u8]
, and return it as &self
with the same lifetime.
If Self
is not well-defined for all possible bit values, the bytes should be validated,
and Self::Error
should be returned if they are not valid.
Safety
Implementations of this method may involve unsafe{}
blocks to cast the pointer to the
correct type. It is up to the implementation to reason about the safety.
Takes a byte slice, &[u8]
, and return it as &self
with the same lifetime, assuming that
this byte slice has previously been run through VarULE::parse_byte_slice()
with success.
There is no need to perform any validation here, this should almost always be a straight pointer cast.
Safety
Callers of this method must take care to ensure that bytes
was previously passed through
VarULE::parse_byte_slice()
with success (and was not changed since then).
Implementations of this method may involve unsafe{}
blocks to cast the pointer to the
correct type. It is up to the implementation to reason about the safety, assuming the invariant
above.