hex

Encode and decode data to and from hexadecimal in Rust, with no_std and serde support.

Library
Cargo
v0.4.3
275 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
36 /100 Needs Attention
Development Activity 0
Maintenance 0
Community 64
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
89 /100 Excellent
Architecture 82
Code Quality 90
Innovation 88
Learning Curve 95

hex is a small, dependency-light Rust crate for converting bytes to and from their hexadecimal string representation. Originally extracted from rustc-serialize, it exposes simple top-level encode/decode functions for the common case plus the ToHex and FromHex traits when you need finer control over allocation and output types.

The crate is #![forbid(unsafe_code)] and works in no_std environments through configurable std, alloc, and serde feature flags, making it suitable for everything from application code to embedded targets. It also provides slice-based APIs that let you encode and decode without heap allocation.

What You Get

  • Top-level encode, encode_upper, and decode helpers for the common string case
  • ToHex and FromHex traits implemented for any AsRef<[u8]> and for Vec<u8>/[u8; N]
  • Allocation-free encode_to_slice and decode_to_slice APIs for fixed buffers and no_std
  • Optional serde integration via #[serde(with = "hex")] for de/serializing byte fields
  • A precise FromHexError enum distinguishing invalid characters, odd length, and bad buffer size

Common Use Cases

  • Rendering binary data such as hashes, keys, or checksums as readable hex strings
  • Parsing hex-encoded input from config files, CLIs, or wire formats back into bytes
  • Serializing Vec<u8> fields as hex in JSON and other serde-driven formats
  • Encoding and decoding on embedded or no_std targets without heap allocation

Under The Hood

Architecture

The crate is a single flat module in src/lib.rs with two supporting files, src/error.rs (the FromHexError enum) and src/serde.rs (optional serde glue). Encoding is driven by a BytesToHexChars iterator that walks a byte slice, splitting each byte into high and low nibbles and indexing a static 16-entry lookup table (HEX_CHARS_LOWER/HEX_CHARS_UPPER); it implements ExactSizeIterator so encode can preallocate the output String. Decoding maps each ASCII hex character back to a nibble via val() and recombines pairs, surfacing structured errors for invalid characters, odd input length, or mismatched fixed-buffer sizes. Public entry points layer from the ergonomic encode/decode free functions down to the ToHex/FromHex traits and the allocation-free encode_to_slice/decode_to_slice variants.

Tech Stack

Pure Rust on the 2018 edition with an MSRV of 1.85 and no required runtime dependencies. serde (v1.0) is the only optional dependency, gated behind the serde feature. Feature flags form a small lattice — default = ["std"], std = ["alloc"], and standalone alloc and serde — so the crate degrades cleanly from full std down to no_std. Dev-dependencies (criterion, data-encoding, rustc-hex, faster-hex, version-sync, pretty_assertions, serde_json) drive benchmarks against competing crates and version-consistency checks.

Code Quality

High. The crate is #![forbid(unsafe_code)] and #![cfg_attr(not(feature = "std"), no_std)], and its public API is thoroughly documented with runnable doctests. Tests live inline in src/lib.rs and src/error.rs plus integration tests in tests/serde.rs and a version-sync check in tests/version-number.rs, covering round-trips, odd-length and invalid-character errors, empty input, whitespace rejection, and fixed-array decoding. Error handling is explicit through the FromHexError enum rather than panics, and naming (encode_to_slice, decode_to_slice, encode_upper) is consistent and predictable.

API Design

Excellent developer experience. The one-liner hex::encode/hex::decode functions cover the majority of use cases with zero boilerplate, while the ToHex/FromHex traits — blanket-implemented for any AsRef<[u8]> and for Vec<u8>/[u8; N] — give power users control over output type and allocation. The slice-based APIs support no_std and hot paths, and serde integration is a single #[serde(with = "hex")] attribute. Documentation is published on docs.rs with clear examples, making the crate approachable within minutes.

Used by 28 apps in this directory

Python
73%
AGPL 3.0

OpenViking

AI Development · AI Memory · Databases

40,705

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
85
Repo Health
75
Technical
64
Dependency
Built with
Python 73%
TypeScript 12%
Rust 11%
Updated 1 weeks ago
Go
82%
AGPL 3.0

PeerDB

Data Engineering · Databases

3,309

Postgres-native ETL that streams change data capture in real time to Snowflake, BigQuery, ClickHouse, S3, and Kafka — up to 10x faster than general-purpose pipelines, managed through a familiar Postgres SQL interface.

View details
89
Repo Health
76
Technical
66
Dependency
Built with
Go 82%
TypeScript 12%
Updated 1 weeks 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 1 weeks ago
Rust
69%
AGPL 3.0

RustDesk

Networking

126,751

Open-source, self-hosted remote desktop built in Rust — your data, your infrastructure, no third-party cloud.

View details
93
Repo Health
84
Technical
70
Dependency
Built with
Rust 69%
Dart 22%
Updated 1 weeks 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
46%
MIT

Svix

Automation · Developer Tools

3,463

Open source, self-hostable webhook infrastructure that handles delivery, retries, HMAC signing, and multi-tenant event management so you never have to build a webhooks system from scratch.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
Rust 46%
C# 16%
Updated 1 weeks ago
Rust
66%
Apache 2.0

Temps

Analytics · Devops · Monitoring

865

A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.

View details
81
Repo Health
86
Technical
66
Dependency
Built with
Rust 66%
TypeScript 33%
Updated 1 weeks ago
Rust
79%
Apache 2.0

TensorZero

Ab Testing Experimentation · AI Development · Monitoring

11,708

TensorZero unifies the LLM gateway, observability, evaluation, optimization, and experimentation stack behind a single OpenAI-compatible API, built in Rust for sub-millisecond p99 latency.

View details
53
Repo Health
87
Technical
68
Dependency
Built with
Rust 79%
TypeScript 15%
Updated 4 months ago
Rust
50%
Apache 2.0

Vibe Kanban

AI Agents · AI Code Assistants · Project Management

28,441

A kanban board for planning work and dispatching Claude Code, Codex, Gemini CLI, and eight other coding agents into isolated git worktrees, then reviewing and merging their diffs from one UI.

View details
72
Repo Health
75
Technical
63
Dependency
Built with
Rust 50%
TypeScript 46%
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