| Crates.io | clippy-utilities |
| lib.rs | clippy-utilities |
| version | 0.2.0 |
| created_at | 2022-02-19 03:43:57.906088+00 |
| updated_at | 2022-06-13 15:23:30.264778+00 |
| description | Utilities funtions for clippy fixing |
| homepage | |
| repository | https://github.com/datenlord/utilities |
| max_upload_size | |
| id | 535010 |
| size | 12,170 |
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.