Struct mycelium_bitfield::example::ExampleBitfield
source · [−]#[repr(transparent)]pub struct ExampleBitfield(_);
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
sourceimpl ExampleBitfield
impl ExampleBitfield
sourcepub const FOO_ENABLED: Pack64<bool, Self> = _
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.
sourcepub const BAR_ENABLED: Pack64<bool, Self> = _
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.
sourcepub const ANOTHER_ENUM: Pack64<AnotherTestEnum, Self> = _
pub const ANOTHER_ENUM: Pack64<AnotherTestEnum, Self> = _
Another enum.
sourcepub const A_BYTE: Pack64<i8, Self> = _
pub const A_BYTE: Pack64<i8, Self> = _
An 8-bit signed integer value.
Who knows what this means.
sourcepub const REST: Pack64<u64, Self> = _
pub const REST: Pack64<u64, Self> = _
..
can be used to create a packing spec for all the remaining
bits in a bitfield.
sourcepub const fn from_bits(bits: u64) -> Self
pub const fn from_bits(bits: u64) -> Self
Constructs a new instance of Self
from the provided raw bits.
sourcepub fn with<T>(self, field: Pack64<T, Self>, value: T) -> Self where
T: FromBits<u64>,
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.
sourcepub fn set<T>(&mut self, field: Pack64<T, Self>, value: T) -> &mut Self where
T: FromBits<u64>,
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.
sourcepub fn get<T>(self, field: Pack64<T, Self>) -> T where
T: FromBits<u64>,
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.
sourcepub fn try_get<T>(self, field: Pack64<T, Self>) -> Result<T, T::Error> where
T: FromBits<u64>,
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 aT
-typed value could be constructed from the bits insrc
Err(T::Error)
ifsrc
does not contain a valid bit pattern for aT
-typed value, as determined byT
’s [FromBits::try_from_bits
implementation.
sourcepub fn assert_valid()
pub fn assert_valid()
Asserts that all the packing specs for this type are valid.
This is intended to be used in unit tests.
Trait Implementations
sourceimpl Binary for ExampleBitfield
impl Binary for ExampleBitfield
sourceimpl Clone for ExampleBitfield
impl Clone for ExampleBitfield
sourcefn clone(&self) -> ExampleBitfield
fn clone(&self) -> ExampleBitfield
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for ExampleBitfield
impl Debug for ExampleBitfield
sourceimpl Display for ExampleBitfield
impl Display for ExampleBitfield
sourceimpl Hash for ExampleBitfield
impl Hash for ExampleBitfield
sourceimpl PartialEq<ExampleBitfield> for ExampleBitfield
impl PartialEq<ExampleBitfield> for ExampleBitfield
sourcefn eq(&self, other: &ExampleBitfield) -> bool
fn eq(&self, other: &ExampleBitfield) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &ExampleBitfield) -> bool
fn ne(&self, other: &ExampleBitfield) -> bool
This method tests for !=
.
impl Copy for ExampleBitfield
impl Eq for ExampleBitfield
impl StructuralEq for ExampleBitfield
impl StructuralPartialEq for ExampleBitfield
Auto Trait Implementations
impl RefUnwindSafe for ExampleBitfield
impl Send for ExampleBitfield
impl Sync for ExampleBitfield
impl Unpin for ExampleBitfield
impl UnwindSafe for ExampleBitfield
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more