pub enum CompactWidth {
One,
Two,
Four,
Eight,
}
Expand description
A minimum width of bytes needed to represent a unsigned integer.
Variants§
One
The byte-width required to represent numbers up to 256 (i.e. a 8-bit number).
Two
The byte-width required to represent numbers up to 256^2 (i.e. a 16-bit number).
Four
The byte-width required to represent numbers up to 256^4 (i.e. a 32-bit number).
Eight
The byte-width required to represent numbers up to 256^8 (i.e. a 64-bit number).
Implementations§
Source§impl CompactWidth
impl CompactWidth
Sourcepub fn from_u64(value: u64) -> Self
pub fn from_u64(value: u64) -> Self
Return the most compact width in bytes (1, 2, 4, or 8) needed to represent a given u64
as a corresponding 8-bit, 16-bit, 32-bit, or 64-bit number.
Sourcepub fn from_u32(value: u32) -> Self
pub fn from_u32(value: u32) -> Self
Return the most compact width in bytes (1, 2, 4) needed to represent a given u32
as a corresponding 8-bit, 16-bit, or 32-bit number.
Sourcepub fn from_u16(value: u16) -> Self
pub fn from_u16(value: u16) -> Self
Return the most compact width in bytes (1 or 2) needed to represent a given u16
as a corresponding 8-bit or 16-bit number.
Sourcepub fn from_u8(_: u8) -> Self
pub fn from_u8(_: u8) -> Self
Return CompactWidth::One
, the only CompactWidth
needed to represent a given u8
.
Sourcepub fn width(&self) -> usize
pub fn width(&self) -> usize
Return the width in bytes of this CompactWidth
.
Sourcepub fn bitmask(&self, position: u8) -> u8
pub fn bitmask(&self, position: u8) -> u8
Encode a CompactWidth
as a 2-bit integer n
such that 2^n gives the bytewidth of the CompactWidth
, and then place that 2-bit number into a u8
at the bit-index of position
.
pub fn decode_fixed_width_bitmask(mask: u8, offset: u8) -> Self
Trait Implementations§
Source§impl Debug for CompactWidth
impl Debug for CompactWidth
Source§impl PartialEq for CompactWidth
impl PartialEq for CompactWidth
impl Eq for CompactWidth
impl StructuralPartialEq for CompactWidth
Auto Trait Implementations§
impl Freeze for CompactWidth
impl RefUnwindSafe for CompactWidth
impl Send for CompactWidth
impl Sync for CompactWidth
impl Unpin for CompactWidth
impl UnwindSafe for CompactWidth
Blanket Implementations§
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more