pub struct BitReader<'a> { /* private fields */ }Expand description
Reads bit-level fields from a byte slice, never panicking.
All methods bound-check and return crate::Error::Truncated
instead of panicking or wrapping, so hostile input surfaces as an
error at the read that needed it.
Implementations§
Source§impl<'a> BitReader<'a>
impl<'a> BitReader<'a>
Sourcepub const fn remaining_bits(&self) -> usize
pub const fn remaining_bits(&self) -> usize
The number of bits still readable.
Sourcepub const fn bit_position(&self) -> usize
pub const fn bit_position(&self) -> usize
The current bit position from the start of the stream.
Sourcepub const fn is_aligned(&self) -> bool
pub const fn is_aligned(&self) -> bool
true when the position is on a byte boundary.
Sourcepub fn byte_align(&mut self)
pub fn byte_align(&mut self)
Discards bits up to the next byte boundary. Aligned readers are unchanged.
Sourcepub fn bits(&mut self, n: usize) -> Result<u64>
pub fn bits(&mut self, n: usize) -> Result<u64>
Reads n bits with the first stream bit becoming the
most-significant bit of the result, for n in 0..=64.
use pith_digest::BitReader;
let mut r = BitReader::new(&[0b1010_0110]);
assert_eq!(r.bits(3).unwrap(), 0b101);
assert_eq!(r.bits(5).unwrap(), 0b0_0110);Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for BitReader<'a>
impl<'a> RefUnwindSafe for BitReader<'a>
impl<'a> Send for BitReader<'a>
impl<'a> Sync for BitReader<'a>
impl<'a> Unpin for BitReader<'a>
impl<'a> UnsafeUnpin for BitReader<'a>
impl<'a> UnwindSafe for BitReader<'a>
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