const_arithmetic
const_arithmetic
is a crate dedicated to exploiting Rust's powerful compiler and type generic system to perform integer arithmetics at compile time. This works on stable to circumvent (sort of) #[generic_const_exprs]
Usage
Add the const_arithmetic
crate as a dependency in your Cargo.toml
file:
[]
= "1.0.3"
Import the traits and types from the const_arithmetic
crate:
use *;
Example:
Let's say we want to verify 6 x 4 = 24
. Here is the code snippet that does nothing if the above statement is true and fails to compile if the above statement is false.
use *;
let a = parse_integer!;
let b = parse_integer!;
let c = parse_integer!;
verify_me;
Accordingly, this fails to compile:
use *;
let a = parse_integer!;
let b = parse_integer!;
let c = parse_integer!;
verify_me; // Compilation error
Documentation
Please refer to the API documentation for detailed information and more examples.
Contributing
Please open a PR if you want to change anything. Contributions are welcome.
License
This crate is distributed under the terms of the MIT License.