Integer overflow

Sometimes, when we do operations with integers, we do not take overflows, underflows, and wrappings into account. C will let you do this by default, while Rust will panic when running in debug mode. In release mode, though, these integer overflows can be a big problem.

You can use the integer_arithmetic lint that will suggest using one of the wrapping_...() or saturating_...() methods of the integer to make sure you know what the outcomes of the operation are.

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.