mycelium_bitfield

Trait 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 bools. It can be implemented manually for any user-defined type which has a well-defined bit-pattern representation. For enum types with unsigned integer reprs, it may also be implemented automatically using the enum_from_bits! macro.

Required Associated Constants§

Source

const BITS: u32

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

Required Associated Types§

Source

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 Methods§

Source

fn try_from_bits(bits: B) -> Result<Self, Self::Error>

Attempt to convert bits into a value of this type.

§Returns
  • 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.
Source

fn into_bits(self) -> B

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).

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.

Implementations on Foreign Types§

Source§

impl FromBits<u8> for bool

Source§

const BITS: u32 = 1u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u8) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u8

Source§

impl FromBits<u8> for i8

Source§

const BITS: u32 = 8u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u8) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u8

Source§

impl FromBits<u8> for u8

Source§

const BITS: u32 = 8u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u8) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u8

Source§

impl FromBits<u16> for bool

Source§

const BITS: u32 = 1u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u16) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u16

Source§

impl FromBits<u16> for i8

Source§

const BITS: u32 = 8u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u16) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u16

Source§

impl FromBits<u16> for i16

Source§

const BITS: u32 = 16u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u16) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u16

Source§

impl FromBits<u16> for u8

Source§

const BITS: u32 = 8u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u16) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u16

Source§

impl FromBits<u16> for u16

Source§

const BITS: u32 = 16u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u16) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u16

Source§

impl FromBits<u32> for bool

Source§

const BITS: u32 = 1u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u32) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u32

Source§

impl FromBits<u32> for i8

Source§

const BITS: u32 = 8u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u32) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u32

Source§

impl FromBits<u32> for i16

Source§

const BITS: u32 = 16u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u32) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u32

Source§

impl FromBits<u32> for i32

Source§

const BITS: u32 = 32u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u32) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u32

Source§

impl FromBits<u32> for u8

Source§

const BITS: u32 = 8u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u32) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u32

Source§

impl FromBits<u32> for u16

Source§

const BITS: u32 = 16u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u32) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u32

Source§

impl FromBits<u32> for u32

Source§

const BITS: u32 = 32u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u32) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u32

Source§

impl FromBits<u64> for bool

Source§

const BITS: u32 = 1u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u64) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u64

Source§

impl FromBits<u64> for i8

Source§

const BITS: u32 = 8u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u64) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u64

Source§

impl FromBits<u64> for i16

Source§

const BITS: u32 = 16u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u64) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u64

Source§

impl FromBits<u64> for i32

Source§

const BITS: u32 = 32u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u64) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u64

Source§

impl FromBits<u64> for i64

Source§

const BITS: u32 = 64u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u64) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u64

Source§

impl FromBits<u64> for isize

Source§

const BITS: u32 = 64u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u64) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u64

Source§

impl FromBits<u64> for u8

Source§

const BITS: u32 = 8u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u64) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u64

Source§

impl FromBits<u64> for u16

Source§

const BITS: u32 = 16u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u64) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u64

Source§

impl FromBits<u64> for u32

Source§

const BITS: u32 = 32u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u64) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u64

Source§

impl FromBits<u64> for u64

Source§

const BITS: u32 = 64u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u64) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u64

Source§

impl FromBits<u64> for usize

Source§

const BITS: u32 = 64u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u64) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u64

Source§

impl FromBits<u128> for bool

Source§

impl FromBits<u128> for i8

Source§

impl FromBits<u128> for i16

Source§

impl FromBits<u128> for i32

Source§

impl FromBits<u128> for i64

Source§

impl FromBits<u128> for u8

Source§

impl FromBits<u128> for u16

Source§

impl FromBits<u128> for u32

Source§

impl FromBits<u128> for u64

Source§

impl FromBits<u128> for u128

Source§

const BITS: u32 = 128u32

Source§

type Error = Infallible

Source§

fn try_from_bits(f: u128) -> Result<Self, Self::Error>

Source§

fn into_bits(self) -> u128

Source§

impl FromBits<u128> for usize

Source§

impl FromBits<usize> for bool

Source§

impl FromBits<usize> for i8

Source§

impl FromBits<usize> for i16

Source§

impl FromBits<usize> for i32

Source§

impl FromBits<usize> for i64

Source§

impl FromBits<usize> for isize

Source§

impl FromBits<usize> for u8

Source§

impl FromBits<usize> for u16

Source§

impl FromBits<usize> for u32

Source§

impl FromBits<usize> for u64

Source§

impl FromBits<usize> for usize

Implementors§

Source§

impl FromBits<u64> for AnotherTestEnum

Available on trace_macros only.
Source§

const BITS: u32 = 4u32

Source§

type Error = &'static str

Source§

impl FromBits<u64> for TestEnum

Available on trace_macros only.