assert

Macro assert 

Source
assert!() { /* proc-macro */ }
Expand description

The main macro that is used to check a condition and panic if it is false.

§Syntax

assert!(condition: expression);
assert!(condition: expression, message: format_string, args...: format_args);

Parameters:

  • condition: The condition that should be checked. If it evaluates to false, the assertion fails. Can be any expression that evaluates to bool.
  • message: An optional message that is displayed if the assertion fails. This message can contain {} placeholders for dynamic arguments. See format_args for more information.
  • args: Arguments that are only evaluated if the assertion fails. These arguments are passed to format_args to replace the {} placeholders in the message.

§Examples

See the crate-level documentation for examples.