2 unstable releases

0.2.0 Jun 13, 2022
0.1.0 Feb 19, 2022

#2306 in Algorithms

Download history 452/week @ 2024-01-13 591/week @ 2024-01-20 463/week @ 2024-01-27 333/week @ 2024-02-03 151/week @ 2024-02-10 485/week @ 2024-02-17 527/week @ 2024-02-24 542/week @ 2024-03-02 426/week @ 2024-03-09 1062/week @ 2024-03-16 548/week @ 2024-03-23 412/week @ 2024-03-30 441/week @ 2024-04-06 467/week @ 2024-04-13 385/week @ 2024-04-20 292/week @ 2024-04-27

1,606 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