Struct bit_manager::BitWriter
[−]
[src]
pub struct BitWriter<T: Write> { /* fields omitted */ }
A wrapper for any type implementing io::Write
that allows the writing of individual bits
Example
extern crate bit_manager; use bit_manager::BitWriter; let mut writer = BitWriter::new(Vec::new()); writer.write_bits(&[false, true, false, false, true, false, false, false]).unwrap(); writer.write(b'i').unwrap(); assert_eq!(writer.into_inner().unwrap(), b"Hi");
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.
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 write<V: BitWritable>(&mut self, value: V) -> Result<()>
[src]
Writes a value.
fn write_using<V, C>(&mut self, value: V, converter: &C) -> Result<()> where
C: BitWrite<V>,
[src]
C: BitWrite<V>,
Writes a value using a converter.
fn write_bit(&mut self, bit: bool) -> Result<()>
[src]
Writes a single bit.
fn write_bits(&mut self, bits: &[bool]) -> Result<usize>
[src]
Writes as many bits as possible into a buffer. Returns the number of bits written.
fn write_byte(&mut self, byte: u8) -> Result<()>
[src]
Writes a single byte.
fn write_bytes(&mut self, bytes: &[u8]) -> Result<usize>
[src]
Writes as many bytes as possible into a buffer. Returns the number of bytes written.
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.