Macro checked_ops
macro_rules! checked_ops {
($($rest:tt)+) => { ... };
}Expand description
Takes an expression and expands it into a “checked” form.
Supported operators are: +, -, *, /, % (binary operators),
and as (cast).
Supported operands are: number literals, simple variables (single-token expressions), and pathenthesized expressions.
§Examples
assert_eq!(checked_ops!(1 - 2), Some(-1));
assert_eq!(checked_ops!(1u32 - 2), None);
assert_eq!(checked_ops!((1 - 2) as u32), None);
assert_eq!(checked_ops!(1 / 0), None);§Caveats
- Non-single-token operands such as field expressions
(
struct.attribute), function calls (function()), and paths (std::u32::MAX) are not supported. - Operators not listed above are not yet supported.
These include unary
-(negative),<<, and>>(bit shift). - A long expression causes “recursion limit reached while expanding the macro” error.