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

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]

[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]

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

[src]

Aligns the stream to the next byte.

[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> BitWrite for BitWriter<T>
[src]

[src]

Writes a single bit.

[src]

Writes a single byte. Read more

[src]

Writes a value that implements [BitStore] using the write_to function. Read more

[src]

Writes a value using a converter that implements [BitConvert] with the write_value_to function. Read more

[src]

Writes values that implement [BitStore] from a buffer. Returns the number of values written. Read more

[src]

Writes values using a converter that implements [BitConvert] from a buffer. Returns the number of values written. Read more

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

[src]

Executes the destructor for this type. Read more