Expand description
§assert_not - Inverse Assertion Macros for Rust
This crate provides macros for asserting that conditions are NOT true,
which is the inverse behavior of Rust’s standard assert! macro.
§Why use assert_not?
While assert! verifies that a condition is true, sometimes you need to ensure
that a condition is explicitly false. Instead of writing assert!(!condition),
assert_not!(condition) provides clearer intent and better readability.
§Features
assert_not!- Runtime assertion that panics if condition is truedebug_assert_not!- Debug-only assertion (removed in release builds)no_stdcompatible - Works in embedded and bare-metal environments- Zero runtime overhead in release builds (for debug variants)
- Custom error messages with format string support
§Quick Start
Add to your Cargo.toml:
# For tests (most common)
[dev-dependencies]
assert-not = "0.1.0"
# For runtime use
[dependencies]
assert-not = "0.1.0"Basic usage:
use assert_not::assert_not;
assert_not!(false); // ✓ Passes
let x = 5;
assert_not!(x == 0, "x should not be zero"); // ✓ With message§Common Use Cases
use assert_not::assert_not;
#[derive(PartialEq)]
enum Status { Error, Ok }
let value = 10;
let state = Status::Ok;
let config = Some("config");
// Input validation
assert_not!(value < 0, "Value must be positive");
// State validation
assert_not!(state == Status::Error, "Cannot proceed in error state");
// Optional values
assert_not!(config.is_none(), "Configuration required");§Comparison with Standard Assertions
use assert_not::assert_not;
let x = 5;
let list = vec![1, 2, 3];
// Instead of:
assert!(x != 0);
assert!(!list.is_empty());
// You can write:
assert_not!(x == 0);
assert_not!(list.is_empty());Modules§
- examples
- More Examples
Macros§
- assert_
not - Asserts that a condition is NOT true.
- debug_
assert_ not - Debug-only version of
assert_not!.