Struct bit_manager::prelude::BitWriter
[−]
[src]
pub struct BitWriter<T: Write> { /* fields omitted */ }
A wrapper for any type implementing io::Write
that allows the writing of individual bits
Closing
When the writer is dropped, the contents of its buffer will be written out. However, any errors that happen in the process of closing the buffer when the writer is dropped will be ignored. Code that wishes to handle such errors must manually call close before the writer is dropped. The internal buffer will be returned on success.
A failed flush operation will result in Error::BufferClosed
. Any further operations
will also fail because the internal buffer may have been corrupted.
Example
use bit_manager::{BitWriter, BitWrite}; let mut writer = BitWriter::new(Vec::new()); writer.write_bit(false)?; writer.write_bit(true)?; writer.write_bit(true)?; writer.write_byte(0b01110101)?; assert_eq!(writer.into_inner()?, [0b01101110u8, 0b10100000u8]);
Methods
impl<T: Write> BitWriter<T>
[src]
fn new(writer: T) -> BitWriter<T>
[src]
Creates a new bit writer with the given writer. Uses Precision::Byte
by default.
fn new_with_precision(writer: T, precision: Precision) -> BitWriter<T>
[src]
Creates a new bit writer with the given writer and Precision
fn is_aligned(&self) -> bool
[src]
Returns true
if the internal buffer is aligned to a byte.
fn align(&mut self) -> Result<()>
[src]
Aligns the stream to the next byte.
fn flush(&mut self) -> Result<usize>
[src]
Flushes the internal buffer. Returns the number of bits left in the buffer.
fn into_inner(self) -> Result<T>
[src]
Returns the inner writer after closing and flushing the internal buffer.
fn close(self) -> Result<()>
[src]
Flushes the remaining internal buffer and aligns bits to the next byte using the precision of this writer.
Trait Implementations
impl<T: Write> BitWrite for BitWriter<T>
[src]
fn write_bit(&mut self, bit: bool) -> Result<()>
[src]
Writes a single bit.
fn write_byte(&mut self, byte: u8) -> Result<()>
[src]
Writes a single byte. Read more
fn write<T: BitStore>(&mut self, value: &T) -> Result<()>
[src]
Writes a value that implements [BitStore
] using the write_to
function. Read more
fn write_using<T, C>(&mut self, value: &T, converter: &C) -> Result<()> where
C: BitConvert<T>,
[src]
C: BitConvert<T>,
Writes a value using a converter that implements [BitConvert
] with the write_value_to
function. Read more
fn write_buffer<T, B>(&mut self, buffer: B) -> usize where
T: BitStore,
B: AsRef<[T]>,
[src]
T: BitStore,
B: AsRef<[T]>,
Writes values that implement [BitStore
] from a buffer. Returns the number of values written. Read more
fn write_buffer_using<T, B, C>(&mut self, buffer: B, converter: &C) -> usize where
B: AsRef<[T]>,
C: BitConvert<T>,
[src]
B: AsRef<[T]>,
C: BitConvert<T>,
Writes values using a converter that implements [BitConvert
] from a buffer. Returns the number of values written. Read more