bincode

A compact, zero-fluff binary encoder and decoder for turning Rust structs into space-efficient byte streams.

Library
Cargo
v3.0.0
3,060 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
42 /100 Fair
Development Activity 0
Maintenance 20
Community 48
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
76 /100 Good
Architecture 80
Code Quality 78
Innovation 74
Learning Curve 70

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_slice for in-memory buffers, plus encode_into_std_write / decode_from_std_read for files and sockets and encode_into_slice for pre-allocated or embedded targets
  • Encode, Decode, and BorrowDecode derive macros (via the derive feature) so structs and enums opt in without hand-written impls
  • A Configuration builder for choosing little/big endian byte order, fixed vs. variable-length integer encoding, and an optional size limit to guard against untrusted input
  • Optional serde integration (bincode::serde module) for encoding/decoding types that only implement serde’s Serialize/Deserialize
  • no_std support via the alloc feature, with atomics, HashMap/HashSet (behind std), 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

Rust
93%
Apache 2.0

Murr

Databases

117

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.

View details
73
Repo Health
72
Technical
75
Dependency
Built with
Rust 93%
Updated 1 weeks ago
Rust
85%
AGPL 3.0

ParadeDB

Analytics · Databases · Search

9,436

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.

View details
89
Repo Health
87
Technical
68
Dependency
Built with
Rust 85%
PLpgSQL 15%
Updated 6 days ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

40,397

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.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 6 days ago
Rust
79%
AGPL 3.0

Spacedrive

Collaboration · File Storage

39,292

One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.

View details
84
Repo Health
84
Technical
63
Dependency
Built with
Rust 79%
TypeScript 18%
Updated 2 weeks ago
Rust
98%

Stalwart

Collaboration

15,268

All-in-one secure mail and collaboration server covering IMAP, JMAP, SMTP, CalDAV, CardDAV, and WebDAV in a single memory-safe Rust binary.

View details
88
Repo Health
81
Technical
65
Dependency
Built with
Rust 98%
Updated 1 weeks ago
Rust
93%
Other

Tabby

AI Code Assistants

33,924

Self-hosted AI coding assistant — run GitHub Copilot-grade code completion on your own hardware with no cloud dependency.

View details
55
Repo Health
78
Technical
61
Dependency
Built with
Rust 93%
Updated 4 months ago
Rust
71%
MIT

Trieve

AI Development · Developer Tools · Search

2,721

All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.

View details
42
Repo Health
74
Technical
65
Dependency
Built with
Rust 71%
Updated 9 months ago
Rust
97%
Apache 2.0

Volga

Data Engineering

161

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.

View details
61
Repo Health
67
Technical
72
Dependency
Built with
Rust 97%
Updated 1 months ago

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