pub trait Specifier {
type Bytes;
type InOut;
const BITS: usize;
// Required methods
fn into_bytes(input: Self::InOut) -> Result<Self::Bytes, OutOfBounds>;
fn from_bytes(
bytes: Self::Bytes,
) -> Result<Self::InOut, InvalidBitPattern<Self::Bytes>>;
}
Expand description
Trait implemented by all bitfield specifiers.
Should generally not be implemented directly by users but through the macros provided by the crate.
§Note
These can be all unsigned fixed-size primitives,
represented by B1, B2, ... B64
and enums that
derive from BitfieldSpecifier
.
Required Associated Constants§
Required Associated Types§
Required Methods§
Sourcefn into_bytes(input: Self::InOut) -> Result<Self::Bytes, OutOfBounds>
fn into_bytes(input: Self::InOut) -> Result<Self::Bytes, OutOfBounds>
Converts some bytes into the in-out type.
§Errors
If the in-out type is out of bounds. This can for example happen if your
in-out type is u8
(for B7
) but you specified a value that is bigger
or equal to 128 which exceeds the 7 bits.
Sourcefn from_bytes(
bytes: Self::Bytes,
) -> Result<Self::InOut, InvalidBitPattern<Self::Bytes>>
fn from_bytes( bytes: Self::Bytes, ) -> Result<Self::InOut, InvalidBitPattern<Self::Bytes>>
Converts the given bytes into the in-out type.
§Errors
If the given byte pattern is invalid for the in-out type. This can happen for example for enums that have a number of variants which is not equal to the power of two and therefore yields some invalid bit patterns.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.