bitvec
Rust crate for addressing memory bit by bit with bit-precise slices, vectors, and bitfields.
Repository Health
Technical Analysis
Bitvec is a foundational Rust crate for working with memory at the level of individual bits. It specializes the standard library’s slices, arrays, and vectors so that a collection of bool values is stored one bit per element, comparable to C++‘s std::bitset and std::vector<bool>, while also allowing a memory region to be divided into arbitrary bitfields like Erlang binaries.
When you need to view memory as bit-addressed rather than byte-addressed, bitvec provides BitSlice, BitArray, BitBox, and BitVec types with configurable bit ordering and storage integers, giving precise control over packed collections, bitfield access, and wire-protocol layouts.
What You Get
BitSlice,BitArray,BitBox, andBitVectypes mirroring standard slices/arrays/vectors at bit granularity- One-bit-per-
boolpacked storage similar to C++std::bitset - Bitfield access to read and write arbitrary integer-width regions of memory
- Configurable bit ordering (
Lsb0,Msb0) and storage integer types no_stdsupport for embedded targets- Optional
serdeserialization and convenience macros likebits!andbitvec!
Common Use Cases
- Packing boolean flags compactly at one bit each
- Reading and writing bitfields in binary wire protocols and file formats
- Manipulating memory as bit-addressed regions on embedded systems
- Building bit-level data structures where byte alignment would waste space
Under The Hood
Architecture - Bitvec layers its collection types over a low-level pointer model: ptr, index.rs, order.rs, and store.rs define how a bit position maps to an address, ordering, and storage integer, while slice, array, boxed, and vec build the BitSlice/BitArray/BitBox/BitVec collections on top, and field.rs implements bitfield load/store. domain.rs and access.rs handle aliasing and safe shared access. Tech Stack - Rust edition 2021, no_std-capable, depending on radium and funty for the underlying atomics/integer abstractions, with optional serde and alloc features. Code Quality - The repository is unusually thorough, shipping an mdBook, extensive tests, benches, examples, code-coverage config (tarpaulin), CI scripts, and a security policy. API Design - The public types deliberately shadow standard-library collections so existing slice/vec intuition transfers directly, and macros plus generic ordering/storage parameters let users trade convenience for precise control.