macro
assert_eq! — Check two values for equality
Compare values using PartialEq and panic if they are unequal. The operands need suitable Debug implementations for failure reporting. Use it for exact expected results; approximate floating-point comparisons need a deliberate tolerance. Expression result: (). Expected result (not executed): stdout: 'Invoice verified\n'; no stderr. Common mistake: Comparing computed floating-point values for exact equality without considering rounding.
Formal Syntax & Structure
rust syntaxrust
assert_eq!(left, right) or assert_eq!(left, right, "message", arguments...)Working Example
Example Snippetrust
fn main() { let price = 120; let quantity = 3; let total = price * quantity; assert_eq!(total, 360); println!("Invoice verified");}