Crates.io | bits-io |
lib.rs | bits-io |
version | |
source | src |
created_at | 2025-04-11 21:57:57.376002+00 |
updated_at | 2025-04-26 01:01:31.612988+00 |
description | Bit-level IO operations |
homepage | |
repository | |
max_upload_size | |
id | 1630375 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Bit-level IO utilities for Rust, inspired by std::io patterns but designed for working with bits instead of bytes.
Built on top of bitvec
for bit-level abstractions,
nsw-types for non-standard-width types
and bytes for efficient
storage.
bits-io
provides:
BitCursor
- Like std::io::Cursor
, but for bits.BitRead
/ BitWrite
- Like std::io::Read
and Write
, but for bits.Bits
/ BitsMut
- Like bytes::Bytes
and BytesMut
but with bit-level APIsBitBuf
/ BitBufMt
- Like bytes::Buf
and BufMut
BitSlice
- A type alias for &BitSlice<u8, Msb0>
(all APIs here use u8
storage and Msb0 ordering).Mimics std::io::Cursor
but tracks a bit-level position instead of a
byte-level position. In addition to the standard Seek
implementation which
allows seeking by a number of bytes, it also provides BitSeek
which allows
seeking by a number of bits.
BitRead
BitRead
mimics the
std::io::Read
trait, but
its API is defined in terms of reading into "bit slices" instead of u8
slices
(&[u8]
) like std::io::Read
. It leverages the BitSlice
type defined in
the bitvec crate.
BitWrite
BitWrite
mimics the
std::io::Write
trait,
but its API is defined in terms of writing from "bit slices" instead of u8
slices (&[u8]
). It leverages the BitSlice
type defined in the
bitvec crate.
let data: Vec<u8> = vec![0b11100000, 0b11101111];
let mut cursor = BitCursor::from_vec(data);
// Read any non-standard-width type from the cursor
let u3_val = cursor.read_u3().unwrap();
assert_eq!(u3_val, nsw_types::u3::new(0b111));
// Sizes larger than 8 bits require a byte order argument
let u13_val = cursor
.read_u13::<crate::byte_order::NetworkOrder>()
.unwrap();
assert_eq!(u13_val, nsw_types::u13::new(0b0000011101111));