bincode
A compact, zero-fluff binary encoder and decoder for turning Rust structs into space-efficient byte streams.
Repository Health
Technical Analysis
Bincode is a Rust crate for encoding and decoding data using a tiny binary serialization strategy. It converts an in-memory object into a Vec<u8> (or writes it directly to any Writer) using an encoding that is the same size as, or smaller than, the value’s in-memory representation, with no field names or type metadata stored in the output.
Version 2 rebuilt the crate around its own Encode/Decode traits with an optional derive macro, making serde an opt-in dependency rather than a hard requirement, and it works in no_std environments via the alloc feature. It ships a configurable Configuration type for choosing endianness, fixed vs. variable-length integer encoding, and size limits, and is used in projects such as tarpc, WebRender, ipc-channel, and zoxide for RPC payloads, record/replay tooling, and on-disk storage.
What You Get
encode_to_vec/decode_from_slicefor in-memory buffers, plusencode_into_std_write/decode_from_std_readfor files and sockets andencode_into_slicefor pre-allocated or embedded targetsEncode,Decode, andBorrowDecodederive macros (via thederivefeature) so structs and enums opt in without hand-written impls- A
Configurationbuilder for choosing little/big endian byte order, fixed vs. variable-length integer encoding, and an optional size limit to guard against untrusted input - Optional
serdeintegration (bincode::serdemodule) for encoding/decoding types that only implement serde’sSerialize/Deserialize no_stdsupport via theallocfeature, with atomics,HashMap/HashSet(behindstd), and common alloc container support (Vec,String,Box, etc.)
Common Use Cases
- Serializing RPC request/response payloads between Rust services, as used by Google’s tarpc
- Persisting application state or caches to disk in a compact format, as used by zoxide’s directory-frequency database
- Sending structs between processes over an IPC channel, as used by servo/ipc-channel
- Recording and replaying structured event streams for debugging or testing, as used by WebRender
Under The Hood
Architecture: The crate is organized around two trait families, Encode/Decode (plus BorrowDecode for zero-copy borrowing), each driven through a shared Config trait rather than function parameters, so encoding/decoding behavior (endianness, integer width, size limits) is fixed at the type level via Configuration<E, I, L> marker generics. The public entry points in src/lib.rs (encode_to_vec, encode_into_slice, decode_from_slice, encode_into_std_write, decode_from_std_read, etc.) construct a Writer/Reader implementation (SliceWriter, SizeWriter, IoWriter/IoReader for std) and hand it to an EncoderImpl/DecoderImpl in src/enc and src/de, which walk the value’s Encode/Decode implementation. Primitive and container impls live in src/enc/impls.rs, src/de/impls.rs, and src/features/impl_alloc.rs/impl_std.rs, split so alloc- and std-only types (Vec, HashMap, Mutex, Path) are gated behind their respective Cargo features and stay out of no_std builds. Variable-length integers get a dedicated src/varint module with per-width encode/decode tables, and src/features/serde provides a Compat/BorrowCompat bridge so serde-only types can be encoded without the crate’s own derive macros.
Tech Stack: Pure Rust, #![no_std] at the crate root with alloc/std opted back in via Cargo features (default = ["std", "derive"]). The only mandatory runtime dependency is unty (a small type-equality helper); bincode_derive (the proc-macro crate, a sibling in the same Cargo workspace) and serde are both optional, feature-gated dependencies. Dev-dependencies for testing and benchmarking include criterion (benchmarks in benches/varint.rs, benches/inline.rs, benches/string.rs), serde_json, rand, uuid, chrono, glam, ouroboros, and even the older bincode 1.x crate (aliased bincode_1) to test cross-version wire compatibility. MSRV is pinned to Rust 1.85.0 targeting the 2021 edition.
Code Quality: Test coverage is substantial for a serialization crate — 24 files under tests/ covering basic types, derive-generated impls, derive field renaming, serde interop, atomics, allocation-heavy containers, error-size regressions, and a dedicated tests/issues/ directory for regression tests tied to specific bug reports. Error handling is explicit and non-exhaustive: EncodeError and DecodeError in src/error.rs are #[non_exhaustive] enums with named variants (UnexpectedEnd, RefCellAlreadyBorrowed, Io { inner, index }, LockFailed, etc.) rather than a single opaque error type, so callers can match on failure causes. Public items are documented under #![warn(missing_docs, unused_lifetimes)], and the crate carries a docs/spec.md file formally describing the wire format plus a docs/migration_guide.md for bincode-1-to-2 upgrades — an unusually thorough documentation surface for a low-level encoding crate.
API Design: The public API is small and consistent — a handful of encode_*/decode_* free functions distinguished by their input/output medium (slice, Vec, std::io reader/writer, or a generic Reader/Writer), paired with a fluent Configuration builder (config::standard().with_big_endian().with_variable_int_encoding()) instead of a long list of function arguments. The derive feature (on by default) lets most structs and enums opt in with #[derive(Encode, Decode)] and no boilerplate; the crate-level doc comment even ships a runnable example showing derive, encode, and decode in under fifteen lines, plus a compatibility table mapping situations (file/socket vs. in-memory buffer vs. embedded) to the right function pair.
Used by 17 apps in this directory
Murr
Databases
A RocksDB-based NVMe/S3 cache purpose-built for AI inference workloads — a faster Redis replacement optimized for batch, low-latency, zero-copy reads and writes between data pipelines and inference apps.
ParadeDB
Analytics · Databases · Search
Born out of Y Combinator's S2023 batch, ParadeDB is a Postgres extension that delivers Elasticsearch-quality BM25 search and real-time analytics without a separate search cluster to manage.
PostHog
Ab Testing Experimentation · Analytics · Developer Tools
The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.
Spacedrive
Collaboration · File Storage
One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.
Stalwart
Collaboration
All-in-one secure mail and collaboration server covering IMAP, JMAP, SMTP, CalDAV, CardDAV, and WebDAV in a single memory-safe Rust binary.
Tabby
AI Code Assistants
Self-hosted AI coding assistant — run GitHub Copilot-grade code completion on your own hardware with no cloud dependency.
Trieve
AI Development · Developer Tools · Search
All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.
Volga
Data Engineering
A Rust-based real-time data processing engine for AI/ML feature computation, built on Apache DataFusion and Arrow — positioned as an alternative to Flink, Spark, Chronon, and OpenMLDB with unified streaming, batch, and request-time execution.