Function bitrw::with_bit_writer

source ·
pub fn with_bit_writer<R>(
    w: &mut dyn Write,
    f: &mut dyn Fn(&mut dyn BitWrite) -> Result<R>
) -> Result<R>
Expand description

Creates a BitWrite object and pass it to the given scope function f.

let mut v = vec![];
{
    let mut c = std::io::Cursor::new(&mut v);
    bitrw::with_bit_writer(&mut c, &mut |w| {
        w.write(0, 0); //  0
        w.write(1, 1); //  1
        w.write(2, 2); //  3
        w.write(3, 3); //  6
        w.write(4, 4); // 10
        w.write(5, 5); // 15
        w.write(6, 6); // 21
        Ok(())
    });
}
assert_eq!(v, [0b00_011_10_1, 0b0_00101_01, 0b00011]);