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]

[src]

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

[src]

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

[src]

Writes a value.

[src]

Writes a value using a converter.

[src]

Writes a single bit.

[src]

Writes as many bits as possible into a buffer. Returns the number of bits written.

[src]

Writes a single byte.

[src]

Writes as many bytes as possible into a buffer. Returns the number of bytes written.

[src]

Flushes the internal buffer. Returns the number of bits left in the buffer.

[src]

Returns the inner writer after closing and flushing the internal buffer.

[src]

Flushes the remaining internal buffer and aligns bits to the next byte using the precision of this writer.

Trait Implementations

impl<T: Write> Drop for BitWriter<T>
[src]

[src]

Executes the destructor for this type. Read more