Debian Codegraph @

README.md

raw symbols SCIP
1 [Documentation](https://PeterReid.github.io/checked_int_cast)
2
3 The functions that this module exposes attempt to cast from one primitive
4 integer type to another, returning `None` on overflow or underflow.
5
6 # Examples
7 ```rust
8 use checked_int_cast::CheckedIntCast;
9
10 // Returns None if usize has 32 or fewer bits
11 (2u64 << 33).as_usize_checked();
12
13 // Successful cast
14 assert_eq!(127u8.as_i8_checked(), Some(127i8));
15
16 // Overflow
17 assert_eq!(255u8.as_i8_checked(), None);
18
19 // Underflow
20 assert_eq!((-1i8).as_u32_checked(), None);
21 ```