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
The Specifier trait describes a sequence of bits stored in an integer
primitive (the Bytes type) and how to convert them to/from
a more convenient higher-level interface type (the InOut
type).
For example:
- The specifier for
boolconverts between au8with a 1 or 0 bit in the lowest bit position and a nativebool. - The specifier for a unit enum with variants
{0, 1, 14}converts between au16matching those variants and the enum type. - The specifier for a 20-bit struct converts between a
u32and the struct type.
All types used in a #[bitfield] struct must implement this trait, and it
should usually only be implemented with
#[derive(Specifier)].
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 an interface type into its storage type.
§Errors
If the input value is out of bounds, an error will be returned. For
example, the value b100_u8 cannot be converted with B2 because it is
three bits wide.
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 a storage type into its interface type.
§Errors
If the given bit pattern is invalid for the interface type, an error
will be returned. For example, 3_u8 cannot be converted to an enum
which only has variants {0, 1, 2}.
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.