#utilities #overflow #cast

clippy-utilities

Utilities funtions for clippy fixing

2 unstable releases

0.2.0 Jun 13, 2022
0.1.0 Feb 19, 2022

#2374 in Algorithms

Download history 184/week @ 2025-09-25 69/week @ 2025-10-02 25/week @ 2025-10-09 176/week @ 2025-10-16 137/week @ 2025-10-23 74/week @ 2025-10-30 304/week @ 2025-11-06 111/week @ 2025-11-13 419/week @ 2025-11-20 41/week @ 2025-11-27 201/week @ 2025-12-04 96/week @ 2025-12-11 74/week @ 2025-12-18 53/week @ 2025-12-25 48/week @ 2026-01-01 27/week @ 2026-01-08

205 downloads per month
Used in 6 crates

MIT license

9KB
187 lines

Cast and Overflow utilities

This utility lib helps for type casting and integer operation overflow checking. The following code block shows examples:

let a: u64 = 10;
let b: i64 = a.numeric_cast();
let a = 1.overflow_add(1);

For the first example, as conversion is not perfect for slicently lossy conversion while try_from and try_into are better. However they're too verbose in most cases, so we wrap it in the cast method and make it panic while these try_xxx methods failed.

For the second example, rust std lib provides overflow checking methods such as overflowing_add. The methods provided in this lib are one step futher, panicing when any overflow happens.

Dependencies

~23KB