bitstream_io

Struct BitQueue

Source
pub struct BitQueue<E: Endianness, N: Numeric> { /* private fields */ }
Expand description

A queue for efficiently pushing bits onto a value and popping them off a value.

Implementations§

Source§

impl<E: Endianness, N: Numeric> BitQueue<E, N>

Source

pub fn new() -> BitQueue<E, N>

Returns a new empty queue

Source

pub fn from_value(value: N, bits: u32) -> BitQueue<E, N>

Creates a new queue from the given value with the given size Panics if the value is larger than the given number of bits.

Source

pub fn set(&mut self, value: N, bits: u32)

Sets the queue to a given value with the given number of bits Panics if the value is larger than the given number of bits

Source

pub fn value(self) -> N

Consumes the queue and returns its current value

Source

pub fn len(&self) -> u32

Returns the total bits in the queue

Source

pub fn max_len(&self) -> u32

Returns the maximum bits the queue can hold

Source

pub fn remaining_len(&self) -> u32

Returns the remaining bits the queue can hold

Source

pub fn is_empty(&self) -> bool

Returns true if the queue is empty

Source

pub fn is_full(&self) -> bool

Returns true if the queue is full

Source

pub fn clear(&mut self)

Drops all values in the queue

Source

pub fn all_0(&self) -> bool

Returns true if all bits remaining in the queue are 0

Source

pub fn all_1(&self) -> bool

Returns true if all bits remaining in the queue are 1

Source

pub fn push(&mut self, bits: u32, value: N)

Pushes a value with the given number of bits onto the tail of the queue Panics if the number of bits pushed is larger than the queue can hold.

Source

pub fn push_fixed<const B: u32>(&mut self, value: N)

Pushes a value with the given number of bits onto the tail of the queue Panics if the number of bits pushed is larger than the queue can hold.

Source

pub fn pop(&mut self, bits: u32) -> N

Pops a value with the given number of bits from the head of the queue Panics if the number of bits popped is larger than the number of bits in the queue.

Source

pub fn pop_fixed<const B: u32>(&mut self) -> N

Pops a value with the given number of bits from the head of the queue

Source

pub fn pop_all(&mut self) -> N

Pops all the current bits from the queue and resets it to an empty state.

Source

pub fn drop(&mut self, bits: u32)

Drops the given number of bits from the head of the queue without returning them. Panics if the number of bits dropped is larger than the number of bits in the queue.

Source

pub fn pop_0(&mut self) -> u32

Pops all 0 bits up to and including the next 1 bit and returns the amount of 0 bits popped

Source

pub fn pop_1(&mut self) -> u32

Pops all 1 bits up to and including the next 0 bit and returns the amount of 1 bits popped

Source§

impl<E: Endianness> BitQueue<E, u8>

Source

pub fn to_state(&self) -> usize

Returns the state of the queue as a single value which can be used to perform lookups.

Trait Implementations§

Source§

impl<E: Clone + Endianness, N: Clone + Numeric> Clone for BitQueue<E, N>

Source§

fn clone(&self) -> BitQueue<E, N>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<E: Debug + Endianness, N: Debug + Numeric> Debug for BitQueue<E, N>

Source§

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

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

impl<E: Default + Endianness, N: Default + Numeric> Default for BitQueue<E, N>

Source§

fn default() -> BitQueue<E, N>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<E, N> Freeze for BitQueue<E, N>
where N: Freeze,

§

impl<E, N> RefUnwindSafe for BitQueue<E, N>

§

impl<E, N> Send for BitQueue<E, N>
where N: Send, E: Send,

§

impl<E, N> Sync for BitQueue<E, N>
where N: Sync, E: Sync,

§

impl<E, N> Unpin for BitQueue<E, N>
where N: Unpin, E: Unpin,

§

impl<E, N> UnwindSafe for BitQueue<E, N>
where N: UnwindSafe, E: UnwindSafe,

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 = 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.