Skip to content
Machine scalar casting that meets your expectations
Branch: master
Clone or download
Latest commit feda734 May 8, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ci Improve travis code May 6, 2017
src Only test i128 float conversion if the x128 feature is enabled May 7, 2017
.gitignore prepare for 0.1.0 Feb 7, 2016
.travis.yml Improve travis code May 6, 2017
CHANGELOG.md v0.2.2 May 7, 2017
Cargo.toml v0.2.2 May 7, 2017
LICENSE-APACHE prepare for 0.1.0 Feb 7, 2016
LICENSE-MIT release v0.2.0 Feb 9, 2017
README.md release v0.2.0 Feb 9, 2017

README.md

crates.io crates.io

cast

Ergonomic, checked cast functions for primitive types

extern crate cast;

// `u8` and `u16` are checked cast functions, use them to cast from any numeric
// primitive to `u8`/`u16` respectively
use cast::{u8, u16, Error};

// Infallible operations, like integer promotion, are equivalent to a normal
// cast with `as`
assert_eq!(u16(0u8), 0u16);

// Everything else will return a `Result` depending on the success of the
// operation
assert_eq!(u8(0u16), Ok(0u8));
assert_eq!(u8(256u16), Err(Error::Overflow));
assert_eq!(u8(-1i8), Err(Error::Underflow));
assert_eq!(u8(1. / 0.), Err(Error::Infinite));
assert_eq!(u8(0. / 0.), Err(Error::NaN));

API docs

License

Licensed under either of

at your option.

Contribution

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

You can’t perform that action at this time.