similar-asserts

assert_eq!-style Rust macros with colorized diff output for readable test failures.

Library
Cargo
v2.0.0
170stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
33/100Needs Attention
Development Activity8
Maintenance0
Community44
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
82/100Excellent
Architecture75
Code Quality82
Innovation85
Learning Curve88

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.

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