| Crates.io | assert-not |
| lib.rs | assert-not |
| version | 0.1.0 |
| created_at | 2025-07-25 12:37:18.809683+00 |
| updated_at | 2025-07-25 12:37:18.809683+00 |
| description | A simple, no_std compatible Rust macro that works like the inverse of assert! - passes when condition is false |
| homepage | |
| repository | https://github.com/kazztac/assert-not |
| max_upload_size | |
| id | 1767580 |
| size | 10,868 |
A simple Rust macro that works like the inverse of assert!:
Passes if the condition is false, panics if the condition is true.
assert_not! is a macro for Rust that helps you verify that a condition does not hold.
If the given expression evaluates to false, the test passes.
If it evaluates to true, the macro panics with an optional error message.
While Rust provides the standard assert! macro for asserting that a condition is true,
sometimes you need to ensure a condition is not true.
assert_not! fills this gap with clear intent and easy usage.
use assert_not::assert_not;
let expression = false;
let value = 42;
assert_not!(expression);
assert_not!(expression, "Custom error: {}", value);
use assert_not::assert_not;
let value = 5;
assert_not!(value == 10); // Passes unless value is 10
let foo: Option<i32> = None;
assert_not!(foo.is_some()); // Passes unless foo is Some
let x = 3;
assert_not!(x > 5, "x is too large: {}", x); // Passes unless x > 5, with custom message
expression is false: Nothing happens, test passes.expression is true: Panics, error message displayed (with optional formatting).assert! macro's API style.debug_assert_not!).MIT or Apache-2.0
Feel free to contribute or open issues!