Skip to main content

BitReader

Struct BitReader 

Source
pub struct BitReader<'a, const MSB: bool> { /* private fields */ }
Expand description

A bit cursor that reads from a byte slice.

Implementations§

Source§

impl<'a, const MSB: bool> BitReader<'a, MSB>

Source

pub const fn new(bytes: &'a [u8]) -> Self

A cursor at the first bit of bytes.

MSB is true to read the top of each byte first.

Source

pub const fn at(bytes: &'a [u8], at_bit: usize) -> Self

A cursor at bit at_bit of bytes. A position past the end reads as Short.

Source

pub fn read(&mut self, bits: u32) -> Result<u64, ParseError>

Read the next bits bits as an integer.

§Errors

ParseError::Short if the slice ends inside the field. at is the field’s first byte.

Source

pub fn bit(&mut self) -> Result<bool, ParseError>

Read the next bit.

§Errors

ParseError::Short if the slice ends first.

Source

pub fn skip(&mut self, bits: usize) -> Result<(), ParseError>

Skip bits bits.

§Errors

ParseError::Short if the slice ends inside them. at is the first skipped byte.

Source

pub const fn position(&self) -> usize

Bits read so far.

Source

pub const fn bytes_consumed(&self) -> usize

Bytes touched so far, counting a partly read byte.

Trait Implementations§

Source§

impl<'a, const MSB: bool> Clone for BitReader<'a, MSB>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, const MSB: bool> Debug for BitReader<'a, MSB>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, const MSB: bool> Freeze for BitReader<'a, MSB>

§

impl<'a, const MSB: bool> RefUnwindSafe for BitReader<'a, MSB>

§

impl<'a, const MSB: bool> Send for BitReader<'a, MSB>

§

impl<'a, const MSB: bool> Sync for BitReader<'a, MSB>

§

impl<'a, const MSB: bool> Unpin for BitReader<'a, MSB>

§

impl<'a, const MSB: bool> UnsafeUnpin for BitReader<'a, MSB>

§

impl<'a, const MSB: bool> UnwindSafe for BitReader<'a, MSB>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.