bitvec

Rust crate for addressing memory bit by bit with bit-precise slices, vectors, and bitfields.

Library
Cargo
v1.1.1
1,446stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
39/100Needs Attention
Development Activity0
Maintenance0
Community56
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
82/100Excellent
Architecture93
Code Quality92
Innovation90
Learning Curve55

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, and BitVec types mirroring standard slices/arrays/vectors at bit granularity
  • One-bit-per-bool packed 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_std support for embedded targets
  • Optional serde serialization and convenience macros like bits! and bitvec!

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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search