base64
Correct, fast, and configurable base64 encoding and decoding for Rust, with pluggable alphabets and padding.
Repository Health
Technical Analysis
base64 is the de facto standard Rust crate for encoding and decoding base64 data, downloaded well over a billion times from crates.io. It exposes an Engine trait so applications can choose the alphabet (standard, URL-safe, or a fully custom one) and padding behavior (canonical, no-pad, or custom padding modes) that fit their protocol, while keeping a single consistent API surface.
The crate targets both convenience and raw throughput: high-level encode/decode methods allocate a String or Vec<u8> for you, while slice- and Vec-based variants let performance-sensitive code avoid extra allocations entirely. It also ships streaming Read/Write adapters and a Display wrapper, is no_std-compatible, and forbids unsafe code throughout, making it a safe default for any Rust codebase that needs to move binary data through text-only channels.
What You Get
- A pluggable Engine trait with a ready-to-use GeneralPurpose implementation and pre-configured STANDARD, STANDARD_NO_PAD, URL_SAFE, and URL_SAFE_NO_PAD engines
- Multiple encode/decode entry points — allocating (String/Vec<u8>), in-place (append to an existing String/Vec), and zero-allocation slice variants — so you can trade convenience for throughput as needed
- Streaming DecoderReader and EncoderWriter adapters for std::io::Read/Write, plus a Base64Display wrapper for formatting without allocating
- no_std and alloc-only build support via Cargo features, with #![forbid(unsafe_code)] guaranteeing memory safety throughout
Common Use Cases
- Encoding binary payloads (images, keys, tokens) into JSON, XML, or other text-only API responses
- Decoding Basic Auth headers, JWT segments, and other base64-encoded HTTP artifacts
- Embedding binary assets or hashes as base64 strings in config files, URLs, or data URIs
- Streaming large files through base64 encoding/decoding without buffering the whole payload in memory
Under The Hood
Architecture — The crate centers on an Engine trait (src/engine/mod.rs) that separates the public encode/decode API from the low-level byte-shuffling implementation. GeneralPurpose (src/engine/general_purpose/) is the only shipped implementation today, parameterized by an Alphabet (src/alphabet.rs) and a GeneralPurposeConfig controlling padding behavior; pre-built STANDARD, STANDARD_NO_PAD, URL_SAFE, and URL_SAFE_NO_PAD constants cover the common RFC 4648 cases. Encoding and decoding logic live in dedicated src/encode.rs and src/decode.rs modules, with src/read/decoder.rs and src/write/encoder.rs layering std::io::Read/Write adapters on top of the same engine calls, so streaming and in-memory paths share one correctness-critical core.
Tech Stack — Pure Rust with the 2018 edition and an MSRV of 1.48.0, no runtime dependencies; dev-dependencies (criterion, rand, clap, strum, rstest) are test/benchmark-only. Cargo features (std, alloc, default std) gate std::io support and heap allocation independently, allowing no_std embedded builds when only alloc (or neither) is enabled.
Code Quality — The crate enforces #![forbid(unsafe_code)] and #![deny(missing_docs, ...)] at the crate root, and carries a large first-party test suite (85+ #[test] functions across src/engine/tests.rs, src/read/decoder_tests.rs, src/write/encoder_tests.rs, and tests/), plus fuzz targets under fuzz/ (roundtrip, roundtrip_no_pad, decode_random) run via cargo-fuzz. Naming is consistent (encode/encode_string/encode_slice mirrored by decode/decode_vec/decode_slice), and error types (DecodeError, DecodeSliceError, EncodeSliceError) are explicit enums rather than opaque strings.
API Design — The Engine trait plus a prelude module give both an explicit, discoverable API (use base64::{engine::general_purpose::STANDARD, Engine as _}) and a minimal-footprint shortcut (use base64::prelude::*). A documented table in the crate-level docs maps each use case (allocate vs. append vs. write-into-buffer) to the right method, and every documented example is a runnable doctest, which keeps the extensive documentation verified against the actual API on every cargo test run.
Used by 66 apps in this directory
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.
WrenAI
AI Agents · Analytics · Data Engineering
Open-source GenBI engine that lets AI agents turn natural-language questions into governed SQL, charts, and shareable dashboards across 20+ data sources — no vendor lock-in, no black-box prompts.
Zeron
AI Code Assistants · Developer Tools
A native, Rust-built control plane that runs and steers Claude Code, Codex, Cursor, Devin, and other coding agents from any device, locally by default with optional CRDT-synced multi-device control.