pub struct ExampleBitfield(/* private fields */);
Available on trace_macros only.
Expand description

An example bitfield type.

This type was generated by the following bitfield! macro invocation:

use crate::{
   bitfield,
   example::{AnotherTestEnum, TestEnum},
};

bitfield! {
   /// An example bitfield type.
   ///
   /// This type was generated by the following [`bitfield!`]
   /// macro invocation:
   /// ```
   #[doc = include_str!("example_bitfield.rs")]
   /// ```
   #[derive(PartialEq, Eq, Hash)]
   pub struct ExampleBitfield<u64> {
       /// Six bits of arbitrary meaning.
       pub const SOME_BITS = 6;

       /// A bit flag.
       ///
       /// This is `true` if foo is enabled. What that means is left
       /// as an exercise to the reader.
       pub const FOO_ENABLED: bool;

       /// Another bit flag.
       ///
       /// This is `true` if bar is enabled. What that means is left
       /// as an exercise to the reader.
       pub const BAR_ENABLED: bool;

       /// These bits are reserved and should always be 0.
       const _RESERVED_1 = 2;

       /// An enum value
       pub const TEST_ENUM: TestEnum;

       const _RESERVED_BITS = 4;

       /// Another enum.
       pub const ANOTHER_ENUM: AnotherTestEnum;

       /// An 8-bit signed integer value.
       ///
       /// Who knows what this means.
       pub const A_BYTE: i8;

       /// `..` can be used to create a packing spec for all the remaining
       /// bits in a bitfield.
       pub const REST = ..;
   }
}

Implementations§

source§

impl ExampleBitfield

source

pub const SOME_BITS: Pack64<u64, Self> = _

Six bits of arbitrary meaning.

source

pub const FOO_ENABLED: Pack64<bool, Self> = _

A bit flag.

This is true if foo is enabled. What that means is left as an exercise to the reader.

source

pub const BAR_ENABLED: Pack64<bool, Self> = _

Another bit flag.

This is true if bar is enabled. What that means is left as an exercise to the reader.

source

pub const TEST_ENUM: Pack64<TestEnum, Self> = _

An enum value

source

pub const ANOTHER_ENUM: Pack64<AnotherTestEnum, Self> = _

Another enum.

source

pub const A_BYTE: Pack64<i8, Self> = _

An 8-bit signed integer value.

Who knows what this means.

source

pub const REST: Pack64<u64, Self> = _

.. can be used to create a packing spec for all the remaining bits in a bitfield.

source

pub const fn from_bits(bits: u64) -> Self

Constructs a new instance of Self from the provided raw bits.

source

pub const fn new() -> Self

Constructs a new instance of Self with all bits set to 0.

source

pub const fn bits(self) -> u64

Returns the raw bit representatiion of self as an integer.

source

pub fn with<T>(self, field: Pack64<T, Self>, value: T) -> Self
where T: FromBits<u64>,

Packs the bit representation of value into self at the bit range designated by field, returning a new bitfield.

source

pub fn set<T>(&mut self, field: Pack64<T, Self>, value: T) -> &mut Self
where T: FromBits<u64>,

Packs the bit representation of value into self at the range designated by field, mutating self in place.

source

pub fn get<T>(self, field: Pack64<T, Self>) -> T
where T: FromBits<u64>,

Unpacks the bit range represented by field from self, and converts it into a T-typed value.

Panics

This method panics if self does not contain a valid bit pattern for a T-typed value, as determined by T’s FromBits::try_from_bits implementation.

source

pub fn try_get<T>(self, field: Pack64<T, Self>) -> Result<T, T::Error>
where T: FromBits<u64>,

Unpacks the bit range represented by field from self and attempts to convert it into a T-typed value.

Returns
  • Ok(T) if a T-typed value could be constructed from the bits in src
  • Err(T::Error) if src does not contain a valid bit pattern for a T-typed value, as determined by T’s [FromBits::try_from_bits implementation.
source

pub fn assert_valid()

Asserts that all the packing specs for this type are valid.

This is intended to be used in unit tests.

source

pub fn display_ascii(&self) -> impl Display

Returns a value that formats this bitfield in a multi-line format, using only ASCII characters.

This is equivalent to formatting this bitfield using a {} display specifier, but will never use Unicode box-drawing characters, even when an upstream formatter uses the {:#} fmt::Display specifier. This is intended for use on platforms where Unicode box drawing characters are never available.

source

pub fn display_unicode(&self) -> impl Display

Returns a value that formats this bitfield in a multi-line format, always using Unicode box-drawing characters.

This is equivalent to formatting this bitfield using a {:#} format specifier, but will always use Unicode box-drawing characters, even when an upstream formatter uses the {} fmt::Display specifier.

Trait Implementations§

source§

impl Binary for ExampleBitfield

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Clone for ExampleBitfield

source§

fn clone(&self) -> ExampleBitfield

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ExampleBitfield

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for ExampleBitfield

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<ExampleBitfield> for u64

source§

fn from(ExampleBitfield: ExampleBitfield) -> Self

Converts to this type from the input type.
source§

impl From<u64> for ExampleBitfield

source§

fn from(val: u64) -> Self

Converts to this type from the input type.
source§

impl Hash for ExampleBitfield

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl LowerHex for ExampleBitfield

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl PartialEq for ExampleBitfield

source§

fn eq(&self, other: &ExampleBitfield) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl UpperHex for ExampleBitfield

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Copy for ExampleBitfield

source§

impl Eq for ExampleBitfield

source§

impl StructuralEq for ExampleBitfield

source§

impl StructuralPartialEq for ExampleBitfield

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.