Skip to content

Rust traits for saturating conversion between numeric types

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENCE-APACHE
MIT
LICENCE-MIT
Notifications You must be signed in to change notification settings

staticintlucas/saturate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

saturate   Test StatusCrate VersionRust Version

This crate provides a set of traits for saturating conversion between different numeric types.

The trait SaturatingFrom is implemented by default for all standard numeric types. A blanket implementation of SaturatingInto is also provided, mirroring the standard library's From and Into traits.

Example

use saturate::{SaturatingFrom, SaturatingInto};

assert_eq!(0, u8::saturating_from(-26));
assert_eq!(u32::MAX, i64::MAX.saturating_into());
assert!(f32::saturating_from(u128::MAX).is_infinite()); // out of range => infinity
assert_eq!(u8::MAX, 300.0.saturating_into());

Licence

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Rust traits for saturating conversion between numeric types

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENCE-APACHE
MIT
LICENCE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages