3 ms·
Merely because the "assert" wording is more familiar to more Rust developers because it's similar to typical test code, and can create better error messages wit
by jph 3y ago
Merely because the "assert" wording is more familiar to more Rust developers because it's similar to typical test code, and can create better error messages with details.
For what you're asking, the assertables crate has a macro that will handle any condition:
assert_as_result!(condition) -> Result
And you can alias it as you wish such as:
use assertables::assert_as_result as precondition;
And now you can write what you're suggesting:
precondition(a == b)