checked_int_cast

Crates.iochecked_int_cast
lib.rschecked_int_cast
version1.0.0
sourcesrc
created_at2015-09-07 22:26:22.523656
updated_at2015-12-11 23:58:10.571132
descriptionConversions between primitive integers with overflow and underflow checking
homepagehttps://github.com/PeterReid/checked_int_cast
repositoryhttps://github.com/PeterReid/checked_int_cast
max_upload_size
id2998
size7,897
Peter Reid (PeterReid)

documentation

https://PeterReid.github.io/checked_int_cast

README

Documentation

The functions that this module exposes attempt to cast from one primitive integer type to another, returning None on overflow or underflow.

Examples

use checked_int_cast::CheckedIntCast;

// Returns None if usize has 32 or fewer bits
(2u64 << 33).as_usize_checked();

// Successful cast
assert_eq!(127u8.as_i8_checked(), Some(127i8));

// Overflow
assert_eq!(255u8.as_i8_checked(), None);

// Underflow
assert_eq!((-1i8).as_u32_checked(), None);
Commit count: 2

cargo fmt