[−][src]Struct endio_bit::BitReader
Adds bit-level reading support to something implementing std::io::Read
.
This is accomplished through an internal buffer for storing partially read bytes.
Methods
impl<R: Read> BitReader<R>
[src]
ⓘImportant traits for BitReader<R>pub fn new(inner: R) -> BitReader<R>
[src]
Creates a new BitReader
from something implementing Read
. This will be used as the underlying object to read from.
Examples
Create a BitReader
reading from bytes in memory:
use endio_bit::BitReader; let data = b"\xcf\xfe\xf3\x2c"; let data_reader = &data[..]; let mut reader = BitReader::new(data_reader);
pub fn read_bit(&mut self) -> Res<bool>
[src]
Reads a single bit, returning true for 1, false for 0.
pub fn read_bits(&mut self, count: u8) -> Res<u8>
[src]
Reads 8 bits or less.
The lowest count
bits will be filled by this, the others will be zero.
Reading more than 8 bits is intentionally not supported to keep the interface simple and to avoid having to deal with endianness in any way. Reading more can be accomplished by reading bytes and then reading any leftover bits.
Panics
Panics if count
> 8.
Examples
use endio_bit::BitReader; let data = &b"\xf8"[..]; let mut reader = BitReader::new(data); let value = reader.read_bits(5).unwrap(); assert_eq!(value, 31);
pub fn is_aligned(&self) -> bool
[src]
Returns whether the reader is aligned to the byte boundary.
pub fn align(&mut self)
[src]
Aligns to byte boundary, discarding a partial byte if the BitReader
was not aligned.
pub fn get_ref(&self) -> &R
[src]
Gets a reference to the underlying reader.
pub fn get_mut(&mut self) -> &mut R
[src]
Gets a mutable reference to the underlying reader.
Mutable operations on the underlying reader will corrupt this BitReader
if it is not aligned, so the reference is only returned if the BitReader
is aligned.
Panics if the BitReader
is not aligned.
pub fn get_mut_unchecked(&mut self) -> &mut R
[src]
Gets a mutable reference to the underlying reader.
Use with care: Any reading/seeking/etc operation on the underlying reader will corrupt this BitReader
if it is not aligned.
pub fn into_inner(self) -> R
[src]
Unwraps this BitReader
, returning the underlying reader.
Note that any partially read byte is lost.
Trait Implementations
impl<R: Read> Read for BitReader<R>
[src]
Read bytes from a BitReader
just like from Read
, but with bit shifting support for unaligned reads.
Directly maps to Read
for aligned reads.
fn read(&mut self, buf: &mut [u8]) -> Res<usize>
[src]
unsafe fn initializer(&self) -> Initializer
[src]
read_initializer
)Determines if this Read
er can work with buffers of uninitialized memory. Read more
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
Read all bytes until EOF in this source, placing them into buf
. Read more
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
Read all bytes until EOF in this source, appending them to buf
. Read more
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
Read the exact number of bytes required to fill buf
. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Creates a "by reference" adaptor for this instance of Read
. Read more
fn bytes(self) -> Bytes<Self>
1.0.0[src]
Transforms this Read
instance to an [Iterator
] over its bytes. Read more
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
Creates an adaptor which will chain this stream with another. Read more
fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
Creates an adaptor which will read at most limit
bytes from it. Read more
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,