Trait modular_bitfield::Specifier
source · [−]pub trait Specifier {
type Bytes;
type InOut;
const BITS: usize;
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 Types
Required Associated Constants
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.