pub struct BitfieldStruct24 { /* private fields */ }Expand description
A bitfield struct 24 bits wide.
This type is narrower than its primitive type—there is no
from_primitive method, and TryFrom<u32> is provided for fallible
conversion.
§Declaration
bitfield! {
#[lsb_first]
pub struct BitfieldStruct24: 24 {
/// A 1-bit field with [`U1`] accessors.
pub bit: 1,
/// A 1-bit field with [`bool`] accessors.
pub flag: 1 as bool,
/// A 5-bit field with [`U5`] accessors.
pub multi_bit: 5,
/// A 3-bit field with [`CustomBitint3`] accessors.
pub custom_bitint: 3 as CustomBitint3,
/// An 8-bit field with [`CustomPrimitive8`] accessors.
pub custom_primitive: 8 as CustomPrimitive8,
..
}
}This type is a generated bitfield struct. The bitint type is U24 and the primitive type is u32.
§Fields
§bit
A 1-bit field with U1 accessors.
§flag
A 1-bit field with bool accessors.
§multi_bit
A 5-bit field with U5 accessors.
§custom_bitint
A 3-bit field with CustomBitint3 accessors.
§custom_primitive
An 8-bit field with CustomPrimitive8 accessors.
Implementations§
Source§impl BitfieldStruct24
impl BitfieldStruct24
Sourcepub const fn zero() -> Self
pub const fn zero() -> Self
Returns the type’s zero value.
This method is a const variant of
Bitfield::zero.
Sourcepub const fn new(value: u32) -> Option<Self>
pub const fn new(value: u32) -> Option<Self>
Creates a bitfield value from a primitive value if it is in
range for the bitint type.
This method is a const variant of
Bitfield::new.
Sourcepub const fn new_masked(value: u32) -> Self
pub const fn new_masked(value: u32) -> Self
Creates a bitfield value by masking off the upper bits of a primitive value.
This method is a const variant of
Bitfield::new_masked.
Sourcepub const unsafe fn new_unchecked(value: u32) -> Self
pub const unsafe fn new_unchecked(value: u32) -> Self
Creates a bitfield value from a primitive value without checking
whether it is in range for the bitint type.
This method is a const variant of
Bitfield::new_unchecked.
§Safety
The value must be in range for the bitint type, as determined
by
UBitint::is_in_range.
Sourcepub const fn from_bitint(value: U24) -> Self
pub const fn from_bitint(value: U24) -> Self
Creates a bitfield value from a bitint value.
This is a zero-cost conversion.
Sourcepub const fn to_bitint(self) -> U24
pub const fn to_bitint(self) -> U24
Converts the value to a bitint.
This is a zero-cost conversion.
Sourcepub const fn to_primitive(self) -> u32
pub const fn to_primitive(self) -> u32
Converts the value to the primitive type.
The result is in range for the bitint type, as determined by
UBitint::is_in_range.
This zero-cost conversion is a convenience alias for converting
through the bitint type.
Sourcepub fn replace_bit(&mut self, value: U1) -> U1
pub fn replace_bit(&mut self, value: U1) -> U1
Sourcepub fn replace_flag(&mut self, value: bool) -> bool
pub fn replace_flag(&mut self, value: bool) -> bool
Sourcepub fn with_multi_bit(self, value: U5) -> Self
pub fn with_multi_bit(self, value: U5) -> Self
Sourcepub fn map_multi_bit(self, f: impl FnOnce(U5) -> U5) -> Self
pub fn map_multi_bit(self, f: impl FnOnce(U5) -> U5) -> Self
Sourcepub fn set_multi_bit(&mut self, value: U5)
pub fn set_multi_bit(&mut self, value: U5)
Sourcepub fn replace_multi_bit(&mut self, value: U5) -> U5
pub fn replace_multi_bit(&mut self, value: U5) -> U5
Sourcepub fn custom_bitint(self) -> CustomBitint3
pub fn custom_bitint(self) -> CustomBitint3
Sourcepub fn with_custom_bitint(self, value: CustomBitint3) -> Self
pub fn with_custom_bitint(self, value: CustomBitint3) -> Self
Creates a new value with the given custom_bitint field.
§Field
A 3-bit field with CustomBitint3 accessors.
Sourcepub fn map_custom_bitint(
self,
f: impl FnOnce(CustomBitint3) -> CustomBitint3,
) -> Self
pub fn map_custom_bitint( self, f: impl FnOnce(CustomBitint3) -> CustomBitint3, ) -> Self
Creates a new value by mapping the custom_bitint field to a new one.
§Field
A 3-bit field with CustomBitint3 accessors.
Sourcepub fn set_custom_bitint(&mut self, value: CustomBitint3)
pub fn set_custom_bitint(&mut self, value: CustomBitint3)
Sourcepub fn replace_custom_bitint(&mut self, value: CustomBitint3) -> CustomBitint3
pub fn replace_custom_bitint(&mut self, value: CustomBitint3) -> CustomBitint3
Replaces the custom_bitint field and returns the old value.
§Field
A 3-bit field with CustomBitint3 accessors.
Sourcepub fn update_custom_bitint(
&mut self,
f: impl FnOnce(CustomBitint3) -> CustomBitint3,
) -> CustomBitint3
pub fn update_custom_bitint( &mut self, f: impl FnOnce(CustomBitint3) -> CustomBitint3, ) -> CustomBitint3
Updates the custom_bitint field using a function and returns the old value.
§Field
A 3-bit field with CustomBitint3 accessors.
Sourcepub fn custom_primitive(self) -> CustomPrimitive8
pub fn custom_primitive(self) -> CustomPrimitive8
Sourcepub fn with_custom_primitive(self, value: CustomPrimitive8) -> Self
pub fn with_custom_primitive(self, value: CustomPrimitive8) -> Self
Creates a new value with the given custom_primitive field.
§Field
An 8-bit field with CustomPrimitive8 accessors.
Sourcepub fn map_custom_primitive(
self,
f: impl FnOnce(CustomPrimitive8) -> CustomPrimitive8,
) -> Self
pub fn map_custom_primitive( self, f: impl FnOnce(CustomPrimitive8) -> CustomPrimitive8, ) -> Self
Creates a new value by mapping the custom_primitive field to a new one.
§Field
An 8-bit field with CustomPrimitive8 accessors.
Sourcepub fn set_custom_primitive(&mut self, value: CustomPrimitive8)
pub fn set_custom_primitive(&mut self, value: CustomPrimitive8)
Sourcepub fn replace_custom_primitive(
&mut self,
value: CustomPrimitive8,
) -> CustomPrimitive8
pub fn replace_custom_primitive( &mut self, value: CustomPrimitive8, ) -> CustomPrimitive8
Replaces the custom_primitive field and returns the old value.
§Field
An 8-bit field with CustomPrimitive8 accessors.
Sourcepub fn update_custom_primitive(
&mut self,
f: impl FnOnce(CustomPrimitive8) -> CustomPrimitive8,
) -> CustomPrimitive8
pub fn update_custom_primitive( &mut self, f: impl FnOnce(CustomPrimitive8) -> CustomPrimitive8, ) -> CustomPrimitive8
Updates the custom_primitive field using a function and returns the old value.
§Field
An 8-bit field with CustomPrimitive8 accessors.
Trait Implementations§
Source§impl Bitfield for BitfieldStruct24
Available on doc only.
impl Bitfield for BitfieldStruct24
doc only.Source§fn new(value: u32) -> Option<Self>
fn new(value: u32) -> Option<Self>
bitint type.Source§fn new_masked(value: u32) -> Self
fn new_masked(value: u32) -> Self
Source§unsafe fn new_unchecked(value: u32) -> Self
unsafe fn new_unchecked(value: u32) -> Self
bitint type. Read moreSource§impl Clone for BitfieldStruct24
Available on doc only.
impl Clone for BitfieldStruct24
doc only.Source§fn clone(&self) -> BitfieldStruct24
fn clone(&self) -> BitfieldStruct24
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BitfieldStruct24
Available on doc only.
impl Debug for BitfieldStruct24
doc only.Source§impl From<BitfieldStruct24> for U24
Available on doc only.
impl From<BitfieldStruct24> for U24
doc only.Source§fn from(value: BitfieldStruct24) -> Self
fn from(value: BitfieldStruct24) -> Self
Source§impl From<BitfieldStruct24> for u32
Available on doc only.
impl From<BitfieldStruct24> for u32
doc only.Source§fn from(value: BitfieldStruct24) -> Self
fn from(value: BitfieldStruct24) -> Self
Source§impl From<U24> for BitfieldStruct24
Available on doc only.
impl From<U24> for BitfieldStruct24
doc only.Source§impl Hash for BitfieldStruct24
Available on doc only.
impl Hash for BitfieldStruct24
doc only.Source§impl PartialEq for BitfieldStruct24
Available on doc only.
impl PartialEq for BitfieldStruct24
doc only.Source§impl TryFrom<u32> for BitfieldStruct24
Available on doc only.
impl TryFrom<u32> for BitfieldStruct24
doc only.impl Copy for BitfieldStruct24
doc only.impl Eq for BitfieldStruct24
doc only.impl StructuralPartialEq for BitfieldStruct24
doc only.