pub trait FromBits<B>: Sized {
    type Error: Display;

    const BITS: u32;

    fn try_from_bits(bits: B) -> Result<Self, Self::Error>;
    fn into_bits(self) -> B;
Expand description

Trait implemented by values which can be converted to and from raw bits.

Required Associated Types

The error type returned by Self::try_from_bits when an invalid bit pattern is encountered.

If all bit patterns possible in Self::BITS bits are valid bit patterns for a Self-typed value, this should generally be core::convert::Infallible.

Required Associated Constants

The number of bits required to represent a value of this type.

Required Methods

Attempt to convert bits into a value of this type.

  • Ok(Self) if bits contained a valid bit pattern for a value of this type.
  • Err(Self::Error) if bits is an invalid bit pattern for a value of this type.

Convert self into a raw bit representation.

In general, this will be a low-cost conversion (e.g., for enums, this is generally an as cast).

Implementations on Foreign Types