Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
ci/ | 03-May-2024 | - | 54 | 41 | ||
src/ | 03-May-2024 | - | 769 | 513 | ||
.cargo_vcs_info.json | D | 03-May-2024 | 74 | 6 | 5 | |
.gitignore | D | 03-May-2024 | 28 | 4 | 3 | |
.travis.yml | D | 03-May-2024 | 471 | 36 | 23 | |
Android.bp | D | 03-May-2024 | 1.8 KiB | 59 | 54 | |
CHANGELOG.md | D | 03-May-2024 | 1.3 KiB | 55 | 32 | |
Cargo.toml | D | 03-May-2024 | 1 KiB | 32 | 29 | |
Cargo.toml.orig | D | 03-May-2024 | 682 | 26 | 22 | |
LICENSE | D | 03-May-2024 | 10.6 KiB | 202 | 169 | |
LICENSE-APACHE | D | 03-May-2024 | 10.6 KiB | 202 | 169 | |
LICENSE-MIT | D | 03-May-2024 | 1 KiB | 26 | 22 | |
METADATA | D | 03-May-2024 | 378 | 20 | 19 | |
MODULE_LICENSE_APACHE2 | D | 03-May-2024 | 0 | |||
OWNERS | D | 03-May-2024 | 40 | 2 | 1 | |
README.md | D | 03-May-2024 | 1.4 KiB | 45 | 31 | |
build.rs | D | 03-May-2024 | 192 | 9 | 7 |
README.md
1[](https://crates.io/crates/cast) 2[](https://crates.io/crates/cast) 3 4# `cast` 5 6> Ergonomic, checked cast functions for primitive types 7 8``` rust 9extern crate cast; 10 11// `u8` and `u16` are checked cast functions, use them to cast from any numeric 12// primitive to `u8`/`u16` respectively 13use cast::{u8, u16, Error}; 14 15// Infallible operations, like integer promotion, are equivalent to a normal 16// cast with `as` 17assert_eq!(u16(0u8), 0u16); 18 19// Everything else will return a `Result` depending on the success of the 20// operation 21assert_eq!(u8(0u16), Ok(0u8)); 22assert_eq!(u8(256u16), Err(Error::Overflow)); 23assert_eq!(u8(-1i8), Err(Error::Underflow)); 24assert_eq!(u8(1. / 0.), Err(Error::Infinite)); 25assert_eq!(u8(0. / 0.), Err(Error::NaN)); 26``` 27 28## [API docs](https://docs.rs/cast) 29 30## License 31 32Licensed under either of 33 34- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or 35 http://www.apache.org/licenses/LICENSE-2.0) 36- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) 37 38at your option. 39 40### Contribution 41 42Unless you explicitly state otherwise, any contribution intentionally submitted 43for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 44dual licensed as above, without any additional terms or conditions. 45