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>
impl<const STOP_BIT: u8, const MAXIMUM: u32> Clone for LimitedUnary<STOP_BIT, MAXIMUM>
Source§fn clone(&self) -> LimitedUnary<STOP_BIT, MAXIMUM>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreimpl<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> 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
Mutably borrows from an owned value. Read more