Crate invariants

source ·
Expand description

This crate provides macros and functions for working assertions as an inherent part of your development process. Whether you use assertions for specific points in your code or for buffing up your testing, this crate is for you.

The main motivation for this crate is to make it easy to fill your code with assertions without taking a performance hit in release or in tests. This is because the compiler will optimize away all assertions in release mode and only some in tests, by your choosing.

Basic Usage

There are different assertion levels defined, and macros are provided for each of them. For trace assertions, you can use the tassert! macro:

use invariants::tassert;
fn main() {
    tassert!(false, "This will fail when assert level is equal or lower then {}. Current level is {}.",
        invariants::AssertLevel::Trace, invariants::STATIC_MAX_LEVEL);
}

See the github repository for more information.

Macros

  • Asserts that the given expression is true when Debug level assertions are enabled.
  • Asserts that the given expression is true when Error level assertions are enabled.
  • Asserts that the given expression is true when Info level assertions are enabled.
  • Asserts that the given expression is true when Trace level assertions are enabled.
  • Asserts that the given expression is true when Warn level assertions are enabled.

Structs

Constants

Functions

  • Returns the max assert level. This level is checked in runtime.
  • Sets the max assert level. This level is checked in runtime.

Type Definitions