bitpack 0.2.1

Rust bitpack library, support `no_std` environment.
Documentation
  • Coverage
  • 20%
    2 out of 10 items documented2 out of 8 items with examples
  • Size
  • Source code size: 11.46 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 998.88 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • quininer/bitpack
    2 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • quininer

bitpack

let mut buff = [0; 2];

// write
{
    let mut bitpack = BitPack::<&mut [u8]>::new(&mut buff);
    bitpack.write(10, 4).unwrap();
    bitpack.write(1021, 10).unwrap();
    bitpack.write(3, 2).unwrap();
}

assert_eq!(buff, [218, 255]);

// read
{
    let mut bitpack = BitPack::<&[u8]>::new(&buff);
    assert_eq!(bitpack.read(4).unwrap(), 10);
    assert_eq!(bitpack.read(10).unwrap(), 1021);
    assert_eq!(bitpack.read(2).unwrap(), 3);
}

and, use_std

let mut bitpack_vec = BitPack::<Vec<u8>>::with_capacity(2);
bitpack_vec.write(10, 4).unwrap();
bitpack_vec.write(1021, 10).unwrap();
bitpack_vec.write(3, 2).unwrap();

assert_eq!(bitpack_vec.as_slice(), [218, 255]);

let mut bitpack = BitPack::<&[u8]>::new(bitpack_vec.as_slice());
assert_eq!(bitpack.read(4).unwrap(), 10);
assert_eq!(bitpack.read(10).unwrap(), 1021);
assert_eq!(bitpack.read(2).unwrap(), 3);