macro
debug_assert! — Check an invariant when debug assertions are enabled
Check a condition when debug assertions are enabled. Cargo's dev profile enables these by default and release normally disables them, but settings can override this. The expression still needs to type-check even when not evaluated. Never rely on it for required side effects or safety preconditions. Expression result: (). Expected result (not executed): stdout: 'Range prepared\n'; no stderr. Common mistake: Incrementing a counter inside debug_assert!, causing the update to disappear in some builds.
Formal Syntax & Structure
rust syntaxrust
debug_assert!(condition) or debug_assert!(condition, "message", arguments...)Working Example
Example Snippetrust
fn main() { let lower = 3; let upper = 9; debug_assert!(lower <= upper); println!("Range prepared");}