liveBook · Manning

Assert_eq

The Rust assert_eq! macro compares two expressions and panics when their evaluated values are unequal, reporting the compared values.

How 2 Manning books explain it

Learn Rust in a Month of Lunches

assert_eq! is a Rust macro that panics when two expressions evaluate to unequal values and reports both values.

How it is used
Uses equality assertions to encode guarantees in ordinary code, documentation examples, and automated tests.
How deep it goes
Explains comparison, panic behavior, custom messages, collection checks, and test diagnostics without detailing macro expansion internals.
Examples
Demonstrates even-number validation, Vec mutations, custom messages, and failed tests comparing 2 with 3.
What you can do after
Apply it to verify equal values and diagnose mismatches in Rust programs and tests.

Read how Learn Rust in a Month of Lunches explains assert_eq →

Refactoring to Rust

The Rust assert_eq! macro compares two values for equality and panics when they differ.

How it is used
Uses equality assertions to validate expected results in Rust tests and other Rust code.
How deep it goes
Explains comparison, panic behavior, captured failures, and Debug output, but does not cover macro internals.
Examples
Demonstrates 2 + 2 equaling 4, deliberately failing against 5, and inspecting output from passing and failing tests.
What you can do after
Apply it via Rust’s test framework to compare values and diagnose failures from reported left and right values.

Read how Refactoring to Rust explains assert_eq →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.