Skip to main content

CompactWidth

Enum CompactWidth 

Source
pub enum CompactWidth {
    One,
    Two,
    Four,
    Eight,
}
Expand description

A minimum width of bytes needed to represent a unsigned integer.

Definition

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

Source

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.

Definition.

Source

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.

Definition.

Source

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.

Definition.

Source

pub fn from_u8(_: u8) -> Self

Return CompactWidth::One, the only CompactWidth needed to represent a given u8.

Definition.

Source

pub fn width(&self) -> usize

Return the width in bytes of this CompactWidth.

Source

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.

Source

pub fn decode_fixed_width_bitmask(mask: u8, offset: u8) -> Self

Trait Implementations§

Source§

impl Debug for CompactWidth

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for CompactWidth

Source§

impl PartialEq for CompactWidth

Source§

fn eq(&self, other: &CompactWidth) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for CompactWidth

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.