2 unstable releases

0.2.0 Jun 13, 2022
0.1.0 Feb 19, 2022

#21 in #overflow

Download history 191/week @ 2024-11-16 295/week @ 2024-11-23 274/week @ 2024-11-30 160/week @ 2024-12-07 126/week @ 2024-12-14 99/week @ 2024-12-21 90/week @ 2024-12-28 111/week @ 2025-01-04 129/week @ 2025-01-11 105/week @ 2025-01-18 92/week @ 2025-01-25 128/week @ 2025-02-01 115/week @ 2025-02-08 120/week @ 2025-02-15 125/week @ 2025-02-22 117/week @ 2025-03-01

502 downloads per month
Used in 5 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.


lib.rs:

Traits for datenlord.

Dependencies

~23KB