assert-not

Crates.ioassert-not
lib.rsassert-not
version0.1.0
created_at2025-07-25 12:37:18.809683+00
updated_at2025-07-25 12:37:18.809683+00
descriptionA simple, no_std compatible Rust macro that works like the inverse of assert! - passes when condition is false
homepage
repositoryhttps://github.com/kazztac/assert-not
max_upload_size
id1767580
size10,868
(kazztac)

documentation

https://docs.rs/assert-not

README

assert_not!

A simple Rust macro that works like the inverse of assert!:
Passes if the condition is false, panics if the condition is true.

Overview

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.

Motivation

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.

Usage

use assert_not::assert_not;

let expression = false;
let value = 42;
assert_not!(expression);
assert_not!(expression, "Custom error: {}", value);

Examples

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

Behavior

  • If expression is false: Nothing happens, test passes.
  • If expression is true: Panics, error message displayed (with optional formatting).

Implementation Notes

  • Follows the standard assert! macro's API style.
  • Can be extended for debug-only variants (e.g. debug_assert_not!).

License

MIT or Apache-2.0


Feel free to contribute or open issues!

Commit count: 0

cargo fmt