Skip to content
masterclass Buddy

Rust · Macro

assert!

assert! checks that a Boolean expression is true while the program runs. If it is false, the macro panics; an optional custom message can explain the failure.

Last updated

Since
1.38.0

Syntax

assert!($cond:expr $(,)?);
assert!($cond:expr, $($arg:tt)+);

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • panic!
  • debug_assert!
  • std::fmt

Source: assert in std - Rust. Checked 2026-11-03.