env_assert
env_assert
is a incredibly simple Rust library that allows you to only run an assert!
when an the RUST_ENV_ASSERT
environmental variable is set to true
.
For example:
use env_assert;
$ cargo run
We got here because the environmental variable was not set!
Now lets set our variable and then run
$ RUST_ENV_ASSERT=true cargo run
thread 'main' panicked at 'assertion failed: res.is_positive()', src/main.rs:4:5
What problem does this solve?
Sometimes, the performance increase for running in release mode is significant, but I still want asserts. However, some of those asserts are in a sense debug asserts, and I would rather the program continue than crash when it is deployed. This library lets you have asserts while in release mode, without negatively impacting performance for end users.