Struct LimitedUnary

Source
pub struct LimitedUnary<const STOP_BIT: u8, const MAXIMUM: u32>;
Expand description

A limited unary reader which stops at the given maximum.

Counts non-STOP_BIT values (which must be 0 or 1) until STOP_BIT, or until MAXIMUM is reached. Returns the number of non-STOP_BIT bits, or None if maximum is reached beforehand.

§Examples

use bitstream_io::{BitReader, BitRead, BigEndian, huffman::LimitedUnary};

let data: &[u8] = &[0b001_00000, 0b1111_1111];
let mut r = BitReader::endian(data, BigEndian);
// get 2 bits until the next 1 bit
assert_eq!(r.read_huffman::<LimitedUnary<1, 5>>().unwrap(), Some(2));
// but 5 bits in a row is our maximum
assert_eq!(r.read_huffman::<LimitedUnary<1, 5>>().unwrap(), None);
// the remaining 8 bits are ok to be read
assert_eq!(r.read::<8, u8>().unwrap(), 0b1111_1111);
use bitstream_io::{BitWriter, BitWrite, BigEndian, huffman::LimitedUnary};

let mut w = BitWriter::endian(vec![], BigEndian);
// writes 2 as a regular unary value which stops at the 1 bit
w.write_huffman::<LimitedUnary<1, 5>>(Some(2)).unwrap();
// writing values beyond the maximum does nothing
w.write_huffman::<LimitedUnary<1, 5>>(Some(10)).unwrap();
// writes 5, 0 bits (which is our maximum)
w.write_huffman::<LimitedUnary<1, 5>>(None).unwrap();
// write some 1 bits to pad out the stream
w.write::<8, u8>(0b1111_1111);

assert_eq!(w.into_writer(), &[0b001_00000, 0b1111_1111]);

Trait Implementations§

Source§

impl<const STOP_BIT: u8, const MAXIMUM: u32> Clone for LimitedUnary<STOP_BIT, MAXIMUM>

Source§

fn clone(&self) -> LimitedUnary<STOP_BIT, MAXIMUM>

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<const STOP_BIT: u8, const MAXIMUM: u32> Debug for LimitedUnary<STOP_BIT, MAXIMUM>

Source§

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

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

impl<const STOP_BIT: u8, const MAXIMUM: u32> FromBits for LimitedUnary<STOP_BIT, MAXIMUM>

Source§

type Symbol = Option<u32>

Our returned symbol type
Source§

fn from_bits<F, E>(next: F) -> Result<Self::Symbol, E>
where F: FnMut() -> Result<bool, E>,

Given a fallable bit generator, return our output type Read more
Source§

impl<const STOP_BIT: u8, const MAXIMUM: u32> ToBits for LimitedUnary<STOP_BIT, MAXIMUM>

Source§

type Symbol = Option<u32>

The type we accept to output
Source§

fn to_bits<F, E>(value: Option<u32>, write: F) -> Result<(), E>
where F: FnMut(bool) -> Result<(), E>,

Given a value to generate, write out bits as needed. Read more
Source§

impl<const STOP_BIT: u8, const MAXIMUM: u32> Copy for LimitedUnary<STOP_BIT, MAXIMUM>

Auto Trait Implementations§

§

impl<const STOP_BIT: u8, const MAXIMUM: u32> Freeze for LimitedUnary<STOP_BIT, MAXIMUM>

§

impl<const STOP_BIT: u8, const MAXIMUM: u32> RefUnwindSafe for LimitedUnary<STOP_BIT, MAXIMUM>

§

impl<const STOP_BIT: u8, const MAXIMUM: u32> Send for LimitedUnary<STOP_BIT, MAXIMUM>

§

impl<const STOP_BIT: u8, const MAXIMUM: u32> Sync for LimitedUnary<STOP_BIT, MAXIMUM>

§

impl<const STOP_BIT: u8, const MAXIMUM: u32> Unpin for LimitedUnary<STOP_BIT, MAXIMUM>

§

impl<const STOP_BIT: u8, const MAXIMUM: u32> UnwindSafe for LimitedUnary<STOP_BIT, MAXIMUM>

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 = 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.