Struct bitbit::writer::BitWriter [] [src]

pub struct BitWriter<W: Write> {
    // some fields omitted
}

A BitWriter gives a way to write single bits to a stream.

Methods

impl<W: Write> BitWriter<W>
[src]

fn new(writer: W) -> BitWriter<W>

Constructs a new BitWriter<T>.

Arguments

  • writer - an existing open file or stream (implementing Write).

Examples

let w = try!(File::create("somefile"));
let mut bw = BitWriter::new(w);

fn write_bit(&mut self, is_one: bool) -> Result<()>

Writes a single bit to a BitWriter<T>.

Arguments

is_one - if true, a 1 will be written, otherwise 0 will be written.

Examples

try!(br.write_bit(true));

fn write_byte(&mut self, byte: u8) -> Result<()>

Writes a byte to a BitWriter<T>.

Arguments

byte - the byte to write.

Examples

try!(br.write_byte(byte: u8));

fn write_bits(&mut self, val: u32, nbits: usize) -> Result<()>

Writes a number of bits from a u32 to BitWriter<T>. Will not write more than 32 bits.

Arguments

val - the value containing the bits to write nbits - the number of bits to write

Examples

try!(br.write_bits(0x15, 5));

fn get_ref(&mut self) -> &W

Gets a reference to the underlying stream.