2 unstable releases

0.2.0 Jun 13, 2022
0.1.0 Feb 19, 2022

#18 in #overflow

Download history 208/week @ 2024-07-23 385/week @ 2024-07-30 257/week @ 2024-08-06 263/week @ 2024-08-13 332/week @ 2024-08-20 229/week @ 2024-08-27 189/week @ 2024-09-03 88/week @ 2024-09-10 138/week @ 2024-09-17 101/week @ 2024-09-24 48/week @ 2024-10-01 267/week @ 2024-10-08 153/week @ 2024-10-15 165/week @ 2024-10-22 165/week @ 2024-10-29 157/week @ 2024-11-05

687 downloads per month
Used in 4 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

~22KB