pub struct BitfieldExample { /* private fields */ }_docs_examples and (crate features _docs_examples) only.Expand description
✨ ▫️ 🫗 🗃️ A compact packet header.
It has been generated with the bitfield! macro like this:
bitfield! {
/// A compact packet header.
pub struct BitfieldExample(u16) {
KIND = 0..=3;
VERSION = 4..=7;
LENGTH = 8..=15;
}
}Implementations§
Source§impl BitfieldExample
§Named bit field masks.
These constants represent each field’s occupied bit range, not a field value.
impl BitfieldExample
§Named bit field masks.
These constants represent each field’s occupied bit range, not a field value.
Use them with mask-level methods such as
contains_mask, with_mask and without_mask.
Source§impl BitfieldExample
impl BitfieldExample
Sourcepub const fn is_full(self) -> bool
pub const fn is_full(self) -> bool
Returns true if the raw bits exactly equal the declared field mask.
Sourcepub const fn fields_are_zero(self) -> bool
pub const fn fields_are_zero(self) -> bool
Returns true if all declared field bits are clear.
Sourcepub const fn fields_are_full(self) -> bool
pub const fn fields_are_full(self) -> bool
Returns true if all declared field bits are set.
Sourcepub const fn contains_mask(self, other: Self) -> bool
pub const fn contains_mask(self, other: Self) -> bool
Returns true if all bits in other are set in self.
This is a mask-level predicate. When used with a named field constant, it checks whether every bit occupied by that field is set.
Sourcepub const fn has_extra_bits(self) -> bool
pub const fn has_extra_bits(self) -> bool
Returns true if any bit outside the declared field mask is set.
Sourcepub const fn clear_fields(&mut self)
pub const fn clear_fields(&mut self)
Clears all declared field bits, preserving bits outside the declared field mask.
Sourcepub const fn without_fields(self) -> Self
pub const fn without_fields(self) -> Self
Returns self with all declared field bits cleared, preserving extra bits.
Sourcepub const fn with_mask(self, other: Self) -> Self
pub const fn with_mask(self, other: Self) -> Self
Returns self with all bits in other set.
This is a mask-level operation. Use with_FIELD(value) to replace a field value.
Sourcepub const fn with_mask_if(self, condition: bool, other: Self) -> Self
pub const fn with_mask_if(self, condition: bool, other: Self) -> Self
Returns self with all bits in other set if condition is true.
Sourcepub const fn without_mask(self, other: Self) -> Self
pub const fn without_mask(self, other: Self) -> Self
Returns self with all bits in other cleared.
This is a mask-level operation. It clears the occupied bits, regardless of the current field value.
Sourcepub const fn without_mask_if(self, condition: bool, other: Self) -> Self
pub const fn without_mask_if(self, condition: bool, other: Self) -> Self
Returns self with all bits in other cleared if condition is true.
Source§impl BitfieldExample
impl BitfieldExample
Sourcepub const fn with_kind(self, value: u16) -> Self
pub const fn with_kind(self, value: u16) -> Self
Returns self with the field value replaced, masking it to fit the field width.
Sourcepub const fn try_with_kind(self, value: u16) -> Result<Self, MismatchedCapacity> ⓘ
pub const fn try_with_kind(self, value: u16) -> Result<Self, MismatchedCapacity> ⓘ
Returns self with the checked field value replaced, if it fits.
Sourcepub const fn set_kind(&mut self, value: u16)
pub const fn set_kind(&mut self, value: u16)
Replaces the field value, masking it to fit the field width.
Sourcepub const fn try_set_kind(
&mut self,
value: u16,
) -> Result<(), MismatchedCapacity> ⓘ
pub const fn try_set_kind( &mut self, value: u16, ) -> Result<(), MismatchedCapacity> ⓘ
Replaces the field value, if it fits.
Sourcepub const fn clear_kind(&mut self)
pub const fn clear_kind(&mut self)
Clears the field value.
Sourcepub const fn is_kind_zero(self) -> bool
pub const fn is_kind_zero(self) -> bool
Returns true if the field value is zero.
Sourcepub const fn is_kind_max(self) -> bool
pub const fn is_kind_max(self) -> bool
Returns true if the field value equals its maximum.
Source§impl BitfieldExample
impl BitfieldExample
Sourcepub const fn get_version(self) -> u16
pub const fn get_version(self) -> u16
Returns the field value.
Sourcepub const fn with_version(self, value: u16) -> Self
pub const fn with_version(self, value: u16) -> Self
Returns self with the field value replaced, masking it to fit the field width.
Sourcepub const fn try_with_version(
self,
value: u16,
) -> Result<Self, MismatchedCapacity> ⓘ
pub const fn try_with_version( self, value: u16, ) -> Result<Self, MismatchedCapacity> ⓘ
Returns self with the checked field value replaced, if it fits.
Sourcepub const fn set_version(&mut self, value: u16)
pub const fn set_version(&mut self, value: u16)
Replaces the field value, masking it to fit the field width.
Sourcepub const fn try_set_version(
&mut self,
value: u16,
) -> Result<(), MismatchedCapacity> ⓘ
pub const fn try_set_version( &mut self, value: u16, ) -> Result<(), MismatchedCapacity> ⓘ
Replaces the field value, if it fits.
Sourcepub const fn clear_version(&mut self)
pub const fn clear_version(&mut self)
Clears the field value.
Sourcepub const fn is_version_zero(self) -> bool
pub const fn is_version_zero(self) -> bool
Returns true if the field value is zero.
Sourcepub const fn is_version_max(self) -> bool
pub const fn is_version_max(self) -> bool
Returns true if the field value equals its maximum.
Sourcepub const fn version_span() -> BitSpan<u16>
pub const fn version_span() -> BitSpan<u16>
Returns metadata for this field.
Source§impl BitfieldExample
impl BitfieldExample
Sourcepub const fn get_length(self) -> u16
pub const fn get_length(self) -> u16
Returns the field value.
Sourcepub const fn with_length(self, value: u16) -> Self
pub const fn with_length(self, value: u16) -> Self
Returns self with the field value replaced, masking it to fit the field width.
Sourcepub const fn try_with_length(
self,
value: u16,
) -> Result<Self, MismatchedCapacity> ⓘ
pub const fn try_with_length( self, value: u16, ) -> Result<Self, MismatchedCapacity> ⓘ
Returns self with the checked field value replaced, if it fits.
Sourcepub const fn set_length(&mut self, value: u16)
pub const fn set_length(&mut self, value: u16)
Replaces the field value, masking it to fit the field width.
Sourcepub const fn try_set_length(
&mut self,
value: u16,
) -> Result<(), MismatchedCapacity> ⓘ
pub const fn try_set_length( &mut self, value: u16, ) -> Result<(), MismatchedCapacity> ⓘ
Replaces the field value, if it fits.
Sourcepub const fn clear_length(&mut self)
pub const fn clear_length(&mut self)
Clears the field value.
Sourcepub const fn is_length_zero(self) -> bool
pub const fn is_length_zero(self) -> bool
Returns true if the field value is zero.
Sourcepub const fn is_length_max(self) -> bool
pub const fn is_length_max(self) -> bool
Returns true if the field value equals its maximum.
Sourcepub const fn length_span() -> BitSpan<u16>
pub const fn length_span() -> BitSpan<u16>
Returns metadata for this field.
Trait Implementations§
Source§impl Binary for BitfieldExample
Formats the set as a binary mask over its declared bit domain.
impl Binary for BitfieldExample
Formats the set as a binary mask over its declared bit domain.
Source§impl BitSized<{ $Bitfield::_BITFIELD_BIT_SIZE }> for BitfieldExample
impl BitSized<{ $Bitfield::_BITFIELD_BIT_SIZE }> for BitfieldExample
Source§const BIT_SIZE: usize = _
const BIT_SIZE: usize = _
Source§const MIN_BYTE_SIZE: usize = _
const MIN_BYTE_SIZE: usize = _
Source§fn bit_size(&self) -> usize
fn bit_size(&self) -> usize
Source§fn min_byte_size(&self) -> usize
fn min_byte_size(&self) -> usize
Source§impl Clone for BitfieldExample
impl Clone for BitfieldExample
Source§fn clone(&self) -> BitfieldExample
fn clone(&self) -> BitfieldExample
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ConstInit for BitfieldExample
impl ConstInit for BitfieldExample
impl Copy for BitfieldExample
Source§impl Debug for BitfieldExample
Formats the bitfield as named field values.
impl Debug for BitfieldExample
Formats the bitfield as named field values.
Source§impl DebugExt for BitfieldExamplewhere
BitfieldExample: Debug,
impl DebugExt for BitfieldExamplewhere
BitfieldExample: Debug,
Source§impl Default for BitfieldExample
impl Default for BitfieldExample
Source§impl Display for BitfieldExample
Formats the bitfield as compact named field values.
impl Display for BitfieldExample
Formats the bitfield as compact named field values.
impl Eq for BitfieldExample
Source§impl Hash for BitfieldExample
impl Hash for BitfieldExample
Source§impl LowerHex for BitfieldExample
Formats the set as a hexadecimal mask over its declared bit domain.
impl LowerHex for BitfieldExample
Formats the set as a hexadecimal mask over its declared bit domain.
Source§impl Octal for BitfieldExample
Formats the set as an octal mask over its declared bit domain.
impl Octal for BitfieldExample
Formats the set as an octal mask over its declared bit domain.
Source§impl Ord for BitfieldExample
impl Ord for BitfieldExample
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for BitfieldExample
impl PartialEq for BitfieldExample
Source§impl PartialOrd for BitfieldExample
impl PartialOrd for BitfieldExample
Auto Trait Implementations§
impl Freeze for BitfieldExample
impl RefUnwindSafe for BitfieldExample
impl Send for BitfieldExample
impl Sync for BitfieldExample
impl Unpin for BitfieldExample
impl UnsafeUnpin for BitfieldExample
impl UnwindSafe for BitfieldExample
Blanket Implementations§
Source§impl<T> AnyExt for T
impl<T> AnyExt for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId of Self using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
alloc only.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Source§impl<T> MemExt for Twhere
T: ?Sized,
impl<T> MemExt for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice only.