[][src]Trait bitrw::UseBitWrite

pub trait UseBitWrite: Sized + Write {
    fn use_bit_write<R>(
        &mut self,
        f: &mut dyn Fn(&mut BitWrite) -> Result<R>
    ) -> Result<R> { ... } }

Provided methods

fn use_bit_write<R>(
    &mut self,
    f: &mut dyn Fn(&mut BitWrite) -> Result<R>
) -> Result<R>

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

let mut v = vec![];
{
    use bitrw::UseBitWrite;
    std::io::Cursor::new(&mut v).use_bit_write(&mut |w| {
        w.write(0_u8, 0)?; //  0
        w.write(1_u16, 1)?; //  1
        w.write(2_u32, 2)?; //  3
        w.write(3_u64, 3)?; //  6
        w.write(4_u128, 4)?; // 10
        w.write(5_usize, 5)?; // 15
        w.write(6_u8, 6)?; // 21
        w.write(0xFFFF_u16, 12)?; // 33
        Ok(())
    });
}
assert_eq!(v, [0b00_011_10_1, 0b0_00101_01, 0b111_00011, 0b11111111, 0b1]);
Loading content...

Implementors

impl<T: Write> UseBitWrite for T[src]

fn use_bit_write<R>(
    &mut self,
    f: &mut dyn Fn(&mut BitWrite) -> Result<R>
) -> Result<R>
[src]

Loading content...