BitReader

Struct BitReader 

Source
pub struct BitReader<T: Read> { /* private fields */ }
Expand description

A wrapper for any type implementing io::Read that allows the reading of individual bits

§Example

use bit_manager::{BitReader, BitRead};

let mut reader = BitReader::new([0b01101110u8, 0b10100000u8].as_ref());

assert_eq!(reader.read_bit()?, false);
assert_eq!(reader.read_bit()?, true);
assert_eq!(reader.read_bit()?, true);
assert_eq!(reader.read_byte()?, 0b01110101);

Implementations§

Source§

impl<T: Read> BitReader<T>

Source

pub fn new(reader: T) -> BitReader<T>

Creates a new bit reader with the given reader. Uses Precision::Byte by default.

Source

pub fn new_with_precision(reader: T, precision: Precision) -> BitReader<T>

Creates a new bit reader with the given reader and precision.

Source

pub fn is_aligned(&self) -> bool

Returns true if the internal buffer is aligned to a byte.

Source

pub fn align(&mut self) -> Result<()>

Aligns the stream to the next byte.

Trait Implementations§

Source§

impl<T: Read> BitRead for BitReader<T>

Source§

fn read_bit(&mut self) -> Result<bool>

Reads a single bit.
Source§

fn read_byte(&mut self) -> Result<u8>

Reads a single byte. Read more
Source§

fn read<T: BitStore>(&mut self) -> Result<T>

Reads a value that implements BitStore using the read_from function.
Source§

fn read_using<T, C>(&mut self, converter: &C) -> Result<T>
where C: BitConvert<T>,

Reads a value using a converter that implements BitConvert with the read_value_from function.
Source§

fn read_to_buffer<T, B>(&mut self, buffer: B) -> usize
where T: BitStore, B: AsMut<[T]>,

Reads values that implement BitStore to a buffer. Returns the number of values read.
Source§

fn read_to_buffer_using<T, B, C>(&mut self, buffer: B, converter: &C) -> usize
where B: AsMut<[T]>, C: BitConvert<T>,

Reads values using a converter that implements BitConvert to a buffer. Returns the number of values read.

Auto Trait Implementations§

§

impl<T> Freeze for BitReader<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for BitReader<T>
where T: RefUnwindSafe,

§

impl<T> Send for BitReader<T>
where T: Send,

§

impl<T> Sync for BitReader<T>
where T: Sync,

§

impl<T> Unpin for BitReader<T>
where T: Unpin,

§

impl<T> UnwindSafe for BitReader<T>
where T: 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> 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, 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.