5 ms·
The addition operator just landed in Rust 1.66 (checked_add_signed[1]), but the subtraction one it looks like you'd need to roll your own. [1]: https://github.
by raphlinus 4y ago
The addition operator just landed in Rust 1.66 (checked_add_signed[1]), but the subtraction one it looks like you'd need to roll your own.
[1]: https://github.com/rust-lang/rust/issues/87840 https://github.com/rust-lang/rust/issues/87840
- tialaramex 4y agoYou are probably looking at it wrong. You can now write i32::checked_add_unsigned(some_u32) and i32::checked_sub_unsigned(some_u32) ... which I think are exactly what your parent needs.
- jcranmer 4y agou32::checked_add_signed solves one of the pairs (u32 + i32 -> u32), but there's nothing for the other one (u32 - u32 -> i32).
- tialaramex 4y agoGood point, I'm sure this made sense to me when I wrote it, but I can't ask past me why.