pub struct BitSpan<T> {
pub start: u32,
pub end: u32,
pub width: u32,
pub mask: T,
pub max: T,
}Expand description
▫️ 🗃️ A contiguous span of bits in an integer carrier.
📍 bin
Stores the bounds and derived masks for a packed field.
Fields§
§start: u32First bit in the span.
end: u32Last bit in the span.
width: u32Number of bits in the span.
mask: TShifted mask covering the span.
max: TMaximum value that fits in the span.
Implementations§
Source§impl<T> BitSpan<T>
impl<T> BitSpan<T>
Sourcepub const fn from_parts(start: u32, end: u32, mask: T, max: T) -> Self
pub const fn from_parts(start: u32, end: u32, mask: T, max: T) -> Self
Source§impl<T: Copy> BitSpan<T>
impl<T: Copy> BitSpan<T>
Sourcepub const fn contains_bit(self, bit: u32) -> bool
pub const fn contains_bit(self, bit: u32) -> bool
Returns whether bit is inside the span.
Sourcepub const fn contains_span(self, other: Self) -> bool
pub const fn contains_span(self, other: Self) -> bool
Returns whether other is fully inside self.
Sourcepub const fn is_disjoint(self, other: Self) -> bool
pub const fn is_disjoint(self, other: Self) -> bool
Returns whether both spans share no bits.
Source§impl BitSpan<u8>
impl BitSpan<u8>
Sourcepub const fn try_new(start: u32, end: u32) -> Result<Self, MismatchedBounds> ⓘ
pub const fn try_new(start: u32, end: u32) -> Result<Self, MismatchedBounds> ⓘ
Returns a new checked bit span.
§Errors
Returns an error if start > end or if end exceeds the carrier width.
Sourcepub const fn value_fits(self, value: u8) -> bool
pub const fn value_fits(self, value: u8) -> bool
Returns whether value fits in this span.
Sourcepub const fn set_value(self, bits: u8, value: u8) -> u8
pub const fn set_value(self, bits: u8, value: u8) -> u8
Returns bits with the span value replaced.
The value is masked to fit the span width.
Sourcepub const fn try_set_value(
self,
bits: u8,
value: u8,
) -> Result<u8, MismatchedBounds> ⓘ
pub const fn try_set_value( self, bits: u8, value: u8, ) -> Result<u8, MismatchedBounds> ⓘ
Returns bits with the checked span value replaced.
§Errors
Returns an error if the span is invalid
or if value does not fit within the span width.
Sourcepub const fn is_full_in(self, bits: u8) -> bool
pub const fn is_full_in(self, bits: u8) -> bool
Returns whether every span bit is set in bits.
Sourcepub const fn is_zero_in(self, bits: u8) -> bool
pub const fn is_zero_in(self, bits: u8) -> bool
Returns whether no span bit is set in bits.
Source§impl BitSpan<u16>
impl BitSpan<u16>
Sourcepub const fn try_new(start: u32, end: u32) -> Result<Self, MismatchedBounds> ⓘ
pub const fn try_new(start: u32, end: u32) -> Result<Self, MismatchedBounds> ⓘ
Returns a new checked bit span.
§Errors
Returns an error if start > end or if end exceeds the carrier width.
Sourcepub const fn value_fits(self, value: u16) -> bool
pub const fn value_fits(self, value: u16) -> bool
Returns whether value fits in this span.
Sourcepub const fn set_value(self, bits: u16, value: u16) -> u16
pub const fn set_value(self, bits: u16, value: u16) -> u16
Returns bits with the span value replaced.
The value is masked to fit the span width.
Sourcepub const fn try_set_value(
self,
bits: u16,
value: u16,
) -> Result<u16, MismatchedBounds> ⓘ
pub const fn try_set_value( self, bits: u16, value: u16, ) -> Result<u16, MismatchedBounds> ⓘ
Returns bits with the checked span value replaced.
§Errors
Returns an error if the span is invalid
or if value does not fit within the span width.
Sourcepub const fn is_full_in(self, bits: u16) -> bool
pub const fn is_full_in(self, bits: u16) -> bool
Returns whether every span bit is set in bits.
Sourcepub const fn is_zero_in(self, bits: u16) -> bool
pub const fn is_zero_in(self, bits: u16) -> bool
Returns whether no span bit is set in bits.
Source§impl BitSpan<u32>
impl BitSpan<u32>
Sourcepub const fn try_new(start: u32, end: u32) -> Result<Self, MismatchedBounds> ⓘ
pub const fn try_new(start: u32, end: u32) -> Result<Self, MismatchedBounds> ⓘ
Returns a new checked bit span.
§Errors
Returns an error if start > end or if end exceeds the carrier width.
Sourcepub const fn value_fits(self, value: u32) -> bool
pub const fn value_fits(self, value: u32) -> bool
Returns whether value fits in this span.
Sourcepub const fn set_value(self, bits: u32, value: u32) -> u32
pub const fn set_value(self, bits: u32, value: u32) -> u32
Returns bits with the span value replaced.
The value is masked to fit the span width.
Sourcepub const fn try_set_value(
self,
bits: u32,
value: u32,
) -> Result<u32, MismatchedBounds> ⓘ
pub const fn try_set_value( self, bits: u32, value: u32, ) -> Result<u32, MismatchedBounds> ⓘ
Returns bits with the checked span value replaced.
§Errors
Returns an error if the span is invalid
or if value does not fit within the span width.
Sourcepub const fn is_full_in(self, bits: u32) -> bool
pub const fn is_full_in(self, bits: u32) -> bool
Returns whether every span bit is set in bits.
Sourcepub const fn is_zero_in(self, bits: u32) -> bool
pub const fn is_zero_in(self, bits: u32) -> bool
Returns whether no span bit is set in bits.
Source§impl BitSpan<u64>
impl BitSpan<u64>
Sourcepub const fn try_new(start: u32, end: u32) -> Result<Self, MismatchedBounds> ⓘ
pub const fn try_new(start: u32, end: u32) -> Result<Self, MismatchedBounds> ⓘ
Returns a new checked bit span.
§Errors
Returns an error if start > end or if end exceeds the carrier width.
Sourcepub const fn value_fits(self, value: u64) -> bool
pub const fn value_fits(self, value: u64) -> bool
Returns whether value fits in this span.
Sourcepub const fn set_value(self, bits: u64, value: u64) -> u64
pub const fn set_value(self, bits: u64, value: u64) -> u64
Returns bits with the span value replaced.
The value is masked to fit the span width.
Sourcepub const fn try_set_value(
self,
bits: u64,
value: u64,
) -> Result<u64, MismatchedBounds> ⓘ
pub const fn try_set_value( self, bits: u64, value: u64, ) -> Result<u64, MismatchedBounds> ⓘ
Returns bits with the checked span value replaced.
§Errors
Returns an error if the span is invalid
or if value does not fit within the span width.
Sourcepub const fn is_full_in(self, bits: u64) -> bool
pub const fn is_full_in(self, bits: u64) -> bool
Returns whether every span bit is set in bits.
Sourcepub const fn is_zero_in(self, bits: u64) -> bool
pub const fn is_zero_in(self, bits: u64) -> bool
Returns whether no span bit is set in bits.
Source§impl BitSpan<u128>
impl BitSpan<u128>
Sourcepub const fn try_new(start: u32, end: u32) -> Result<Self, MismatchedBounds> ⓘ
pub const fn try_new(start: u32, end: u32) -> Result<Self, MismatchedBounds> ⓘ
Returns a new checked bit span.
§Errors
Returns an error if start > end or if end exceeds the carrier width.
Sourcepub const fn value_fits(self, value: u128) -> bool
pub const fn value_fits(self, value: u128) -> bool
Returns whether value fits in this span.
Sourcepub const fn set_value(self, bits: u128, value: u128) -> u128
pub const fn set_value(self, bits: u128, value: u128) -> u128
Returns bits with the span value replaced.
The value is masked to fit the span width.
Sourcepub const fn try_set_value(
self,
bits: u128,
value: u128,
) -> Result<u128, MismatchedBounds> ⓘ
pub const fn try_set_value( self, bits: u128, value: u128, ) -> Result<u128, MismatchedBounds> ⓘ
Returns bits with the checked span value replaced.
§Errors
Returns an error if the span is invalid
or if value does not fit within the span width.
Sourcepub const fn is_full_in(self, bits: u128) -> bool
pub const fn is_full_in(self, bits: u128) -> bool
Returns whether every span bit is set in bits.
Sourcepub const fn is_zero_in(self, bits: u128) -> bool
pub const fn is_zero_in(self, bits: u128) -> bool
Returns whether no span bit is set in bits.
Source§impl BitSpan<usize>
impl BitSpan<usize>
Sourcepub const fn try_new(start: u32, end: u32) -> Result<Self, MismatchedBounds> ⓘ
pub const fn try_new(start: u32, end: u32) -> Result<Self, MismatchedBounds> ⓘ
Returns a new checked bit span.
§Errors
Returns an error if start > end or if end exceeds the carrier width.
Sourcepub const fn value_fits(self, value: usize) -> bool
pub const fn value_fits(self, value: usize) -> bool
Returns whether value fits in this span.
Sourcepub const fn set_value(self, bits: usize, value: usize) -> usize
pub const fn set_value(self, bits: usize, value: usize) -> usize
Returns bits with the span value replaced.
The value is masked to fit the span width.
Sourcepub const fn try_set_value(
self,
bits: usize,
value: usize,
) -> Result<usize, MismatchedBounds> ⓘ
pub const fn try_set_value( self, bits: usize, value: usize, ) -> Result<usize, MismatchedBounds> ⓘ
Returns bits with the checked span value replaced.
§Errors
Returns an error if the span is invalid
or if value does not fit within the span width.
Sourcepub const fn is_full_in(self, bits: usize) -> bool
pub const fn is_full_in(self, bits: usize) -> bool
Returns whether every span bit is set in bits.
Sourcepub const fn is_zero_in(self, bits: usize) -> bool
pub const fn is_zero_in(self, bits: usize) -> bool
Returns whether no span bit is set in bits.
Trait Implementations§
impl<T: Copy> Copy for BitSpan<T>
impl<T: Eq> Eq for BitSpan<T>
Source§impl<T: Ord> Ord for BitSpan<T>
impl<T: Ord> Ord for BitSpan<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialEq> PartialEq for BitSpan<T>
impl<T: PartialEq> PartialEq for BitSpan<T>
Source§impl<T: PartialOrd> PartialOrd for BitSpan<T>
impl<T: PartialOrd> PartialOrd for BitSpan<T>
impl<T> StructuralPartialEq for BitSpan<T>
Auto Trait Implementations§
impl<T> Freeze for BitSpan<T>where
T: Freeze,
impl<T> RefUnwindSafe for BitSpan<T>where
T: RefUnwindSafe,
impl<T> Send for BitSpan<T>where
T: Send,
impl<T> Sync for BitSpan<T>where
T: Sync,
impl<T> Unpin for BitSpan<T>where
T: Unpin,
impl<T> UnsafeUnpin for BitSpan<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for BitSpan<T>where
T: UnwindSafe,
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.