Trait mycelium_bitfield::FromBits
source · pub trait FromBits<B>: Sized {
type Error: Display;
const BITS: u32;
// Required methods
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.
This trait is implemented by default for all signed and unsigned integer
types, as well as for bool
s. It can be implemented manually for any
user-defined type which has a well-defined bit-pattern representation. For
enum
types with unsigned integer repr
s, it may also be implemented
automatically using the enum_from_bits!
macro.
Required Associated Types§
sourcetype Error: Display
type Error: Display
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§
Required Methods§
sourcefn try_from_bits(bits: B) -> Result<Self, Self::Error>
fn try_from_bits(bits: B) -> Result<Self, Self::Error>
Attempt to convert bits
into a value of this type.
Returns
Ok(Self)
ifbits
contained a valid bit pattern for a value of this type.Err(Self::Error)
ifbits
is an invalid bit pattern for a value of this type.
Object Safety§
This trait is not object safe.