#[repr(transparent)]
pub struct ExampleBitfield(_);
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

Six bits of arbitrary meaning.

A bit flag.

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

Another bit flag.

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

An enum value

Another enum.

An 8-bit signed integer value.

Who knows what this means.

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

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

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

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

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

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.

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.

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

This is intended to be used in unit tests.

Trait Implementations

Formats the value using the given formatter.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.