4 ms·
That's definitely one way to solve the issue, but I wouldn't say it's the only way. In Rust, you can configure Clippy to ban the usage of +-*/ and require expl
by stonewareslord 5y ago
That's definitely one way to solve the issue, but I wouldn't say it's the only way.
In Rust, you can configure Clippy to ban the usage of +-*/ and require explicit behavior of each calculation. For example, 10u8.checked_add(10) returns an Option<> (similar to Maybe in Haskell) so you can handle overflows. You can also use 1u8.saturating_sub(100) which will not allow wraparound but values will saturate at the max/min.