checked_int_cast

Rust crate for checked integer primitive casts

Latest version: 1.0.0 registry icon
Maintenance score
0
Safety score
0
Popularity score
70
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
1.0.0 0 0 0 0 0

Stability
Latest release:

1.0.0 - This version may not be safe as it has not been updated for a long time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



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);