3 ms·
> Being able to explicitly disable the check when you know > what you want is the right balance, whether it's &+ in > Swift or (better, imo) .wrapping_add
by kibwen 10y ago
> Being able to explicitly disable the check when you know
> what you want is the right balance, whether it's &+ in
> Swift or (better, imo) .wrapping_add() in Rust.
To clarify, Rust does disable the overflow check in release mode (and the benchmarks shown in this post are exactly why, to much heated debate), wrapping instead. `.wrapping_add()` in Rust is just what you use in order to guarantee wrapping behavior in debug mode as well (and also to guard against future changes to the language specification, which currently allows implementations to choose to either panic or wrap on overflow). In order to get the behavior of Swift's basic `+` in Rust, you'd use `.checked_add().unwrap()`.
- arcticbull 10y agoOf course, you're right -- which is a behavior I'm even more in favor of, wherein your debug builds fail fast all the time but your release builds don't.