2 ms·
Why the specialized API, rather than (say) precondition(foo == bar)?
by saagarjha 3y ago
Why the specialized API, rather than (say) precondition(foo == bar)?
- masklinn 3y agoProbably to get better error messages, same as assert_eq, otherwise you need a procedural macro to take appart the entire expression which is way more complicated and more expensive.
- jph 3y agoMerely 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)