similar-asserts
assert_eq!-style Rust macros with colorized diff output for readable test failures.
Repository Health
Technical Analysis
similar-asserts is a Rust crate that enhances the default assertion experience by rendering a colorized diff when an assertion fails. It provides assert_eq!-style macros that compare either the Debug or Serialize representations of two values and print a clear, terminal-colored diff of the differences.
Built on the similar diffing library from the same author, it makes failed assertions in tests far easier to read, especially for large structs, vectors, or serialized data where the default assert_eq! output is hard to scan. Adopting it is usually as simple as swapping the standard macro for similar_asserts::assert_eq!.
What You Get
- Drop-in assert_eq!-style macros that print a colorized diff on failure
- Comparison of either Debug or (optionally) Serialize representations of values
- Far more readable failure output for large structs, collections, and serialized data
Common Use Cases
- Making failed equality assertions in tests easy to scan
- Comparing large data structures where default assert output is unreadable
- Diffing serialized representations of values in tests
Under The Hood
Architecture
The crate defines assert_eq! (and related) macros that, on inequality, format both operands (via Debug or serde Serialize) into strings and feed them to the similar library to compute an inline diff, which is then rendered to the terminal with console for coloring. The comparison and rendering are separated so the same diff engine backs each macro.
Tech Stack
Rust (edition 2024, MSRV 1.85) depending on similar (with inline feature), console for terminal styling, and optional serde for Serialize-based comparisons.
Code Quality
Mature and widely depended upon, with example binaries, a CHANGELOG, and a Makefile-driven workflow. The scope is small and the implementation is stable across releases.
API Design
The macros mirror the standard library signatures exactly, so adoption is a one-line swap, and optional features (unicode, serde) extend behavior without complicating the common case.
Used by 2 apps in this directory
Arroyo
Data Engineering · Analytics
A distributed stream processing engine written in Rust that lets you write SQL to run stateful, real-time computations over data streams with subsecond results.
Meilisearch
Search
Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.