rust-pretty-assertions

Drop-in replacements for Rust's assert_eq! and assert_ne! that print colorful, side-by-side diffs instead of raw Debug dumps.

Library
Cargo
v1.4.1
1,355stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
42/100Fair
Development Activity0
Maintenance20
Community48
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture78
Code Quality82
Innovation62
Learning Curve90

pretty_assertions is a small, focused Rust crate that overwrites the standard library’s assert_eq! and assert_ne! macros with versions that render a colorful, line-by-line diff of the two values under test. When a standard assert_eq! fails, Rust dumps the full Debug representation of both sides and leaves the developer to spot the differing fields by eye; pretty_assertions instead formats both values with {:#?}, diffs the resulting text, and prints only what changed, highlighted in color.

The crate is designed to be imported per-module (use pretty_assertions::{assert_eq, assert_ne};) so it only shadows the macros where explicitly opted into, and is commonly scoped to [dev-dependencies] so it never affects non-test build times. It supports no_std environments via an alloc-only feature flag, and exposes the underlying Comparison and StrComparison types directly for anyone who wants pretty diff output outside of an assertion macro.

With over 190 million downloads on crates.io, it is one of the most widely used testing-ergonomics crates in the Rust ecosystem, valued for the amount of debugging time it saves without requiring any change to test logic.

What You Get

  • Drop-in assert_eq! and assert_ne! macros that match the standard library’s signature, including custom panic messages
  • A colorful, line-by-line diff of the Debug representation of both compared values on failure
  • Comparison and StrComparison types for producing the same diff output outside of an assertion, including string-specific multi-line diffing via AsRef<str>
  • no_std support via an alloc-only feature flag for environments without the standard library
  • An unstable feature flag for opting into in-progress functionality ahead of semantic versioning guarantees
  • Zero required configuration beyond a per-module use import, so it can be adopted incrementally across a codebase

Common Use Cases

  • Faster failed-test triage - a developer scanning CI output for a failing assert_eq! sees only the fields that actually differ instead of two full struct dumps
  • Reviewing snapshot-style struct comparisons - teams testing large structs or nested enums use the diff to immediately see which nested field regressed
  • Debugging string-heavy assertions - StrComparison gives a readable multi-line diff for comparing rendered templates, serialized output, or generated code
  • Enforcing pretty diffs project-wide via Clippy - teams add a disallowed-macros Clippy lint pointing std::assert_eq/assert_ne at the pretty_assertions versions so the ergonomic macros are used consistently across a codebase
  • Test-only dependency with no build-time cost - added under [dev-dependencies] so production compile times and binary size are unaffected

Under The Hood

Architecture The crate is intentionally small and single-purpose: src/lib.rs defines the public Comparison/StrComparison structs and the assert_eq!/assert_ne! macros, while src/printer.rs owns the actual diff rendering (line splitting, coloring, and the write_header/write_lines output routines). Comparisons are lazy — a Comparison::new call only stores references to the two values, and the expensive Debug-formatting and diffing work happens inside Display::fmt, so the cost is paid only when a diff is actually printed (i.e., on assertion failure). The macros themselves expand to an internal @ arm that formats a common panic message, keeping the public macro surface a near-exact match for core::assert_eq!/assert_ne! including support for custom panic messages.

Tech Stack The crate is pure Rust (edition 2018, MSRV 1.35), built with Cargo as a workspace containing the library crate (pretty_assertions) and a separate benchmark crate (pretty_assertions_bench). Runtime dependencies are minimal and deliberately scoped: yansi for terminal color output and diff for line-level text diffing. Feature flags (std, alloc, unstable) gate no_std support and let downstream users opt out of the standard library while still pulling in alloc for the string/vector operations the diff formatting needs.

Code Quality Tests live in pretty_assertions/tests/macros.rs and exercise the macro output directly, including custom-message formatting and edge cases like values that already contain ANSI-like text. The crate enables #![deny(clippy::all, missing_docs, unsafe_code)] at the crate root, meaning every public item requires a doc comment, all Clippy lints are treated as errors, and unsafe code is categorically disallowed — a strict bar for a widely-depended-upon crate. Public types are documented with runnable doctests demonstrating actual usage, which double as both documentation and regression tests. CI is configured via GitHub Actions plus a legacy .travis.yml, with a qvet.yml release-vetting config.

What Makes It Unique Rather than reimplementing assertion logic, pretty_assertions works by formatting both operands with {:#?} and running a generic text diff over the resulting Debug strings — a technique that requires no changes to how types implement PartialEq/Debug and works uniformly across any comparable type, including deeply nested structs and enums. Its explicit semantic-versioning carve-out for output formatting (the diff’s exact appearance can change between minor versions, since it’s meant for humans, not snapshot testing) is an unusually candid piece of API design that keeps the crate free to improve its output without being pinned to compatibility guarantees that don’t apply to display formatting.

Used by 8 apps in this directory

Rust
52%
Other

Cap

Team Chat · Video Conferencing

21,350

Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.

View details
88
Repo Health
81
Technical
65
Dependency
Built with
Rust52%
TypeScript43%
Updated 2 days ago
Rust
100%
Other

Fluree DB

Databases

448

A temporal, verifiable graph database with git-like branching, integrated vector/text/geo search, and RDF/SPARQL/JSON-LD/openCypher support — benchmarked at 10.4x faster than the next database on the full Wikidata dump.

View details
87
Repo Health
74
Technical
65
Dependency
Built with
Rust100%
Updated yesterday
Rust
68%
Other

GitButler

Developer Tools · Devops · AI Development

21,588

Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.

View details
89
Repo Health
84
Technical
68
Dependency
Built with
Rust68%
TypeScript19%
Svelte11%
Updated today
Rust
96%
Apache 2.0

InfluxDB

Databases · Analytics

31,731

Open-source time-series database built for real-time ingest, fast SQL queries, and embedded Python automation — powered by Apache Arrow and Parquet.

View details
84
Repo Health
76
Technical
72
Dependency
Built with
Rust96%
Updated 2 days ago
Rust
96%
Apache 2.0

codex

AI Code Assistants · Developer Tools

119,949

OpenAI's open-source CLI coding agent that reads, edits, and runs code in your terminal using natural language prompts.

View details
89
Repo Health
80
Technical
75
Dependency
Built with
Rust96%
Updated today
Rust
86%
AGPL 3.0

ParadeDB

Search · Databases · Analytics

9,213

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
88
Repo Health
87
Technical
68
Dependency
Built with
Rust86%
PLpgSQL13%
Updated today
Java
92%
Apache 2.0

QuestDB

Databases · Analytics

17,289

A high-performance, open-source time-series database built for financial market data, IoT telemetry, and real-time analytics, combining a zero-GC Java/C++ core with SIMD-accelerated SQL and a WAL-to-Parquet storage engine.

View details
91
Repo Health
86
Technical
67
Dependency
Built with
Java92%
Updated today
Rust
77%
AGPL 3.0

Spacedrive

File Storage · Collaboration

38,876

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

View details
59
Repo Health
84
Technical
64
Dependency
Built with
Rust77%
TypeScript20%
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

Search