macro

debug_assert_eq! — Check equality during diagnostic builds

Compare values for equality when debug assertions are enabled, with the same comparison and diagnostic requirements as assert_eq!. This is useful for redundant internal consistency checks, but not required verification. Expression result: (). Expected result (not executed): stdout: 'Count: 3\n'; no stderr. Common mistake: Assuming both operands always run and relying on an operand to update program state.

Formal Syntax & Structure

rust syntaxrust
debug_assert_eq!(left, right) or debug_assert_eq!(left, right, "message", arguments...)

Working Example

Example Snippetrust
fn main() {    let rows = [2, 4, 6];    let count = rows.iter().count();    debug_assert_eq!(count, rows.len());    println!("Count: {count}");}
Rust Reference