• Home
Name
Date
Size
#Lines
LOC

..--

ci/03-May-2024-5441

src/03-May-2024-769513

.cargo_vcs_info.jsonD03-May-202474 65

.gitignoreD03-May-202428 43

.travis.ymlD03-May-2024471 3623

Android.bpD03-May-20241.8 KiB5954

CHANGELOG.mdD03-May-20241.3 KiB5532

Cargo.tomlD03-May-20241 KiB3229

Cargo.toml.origD03-May-2024682 2622

LICENSED03-May-202410.6 KiB202169

LICENSE-APACHED03-May-202410.6 KiB202169

LICENSE-MITD03-May-20241 KiB2622

METADATAD03-May-2024378 2019

MODULE_LICENSE_APACHE2D03-May-20240

OWNERSD03-May-202440 21

README.mdD03-May-20241.4 KiB4531

build.rsD03-May-2024192 97

README.md

1[![crates.io](https://img.shields.io/crates/d/cast.svg)](https://crates.io/crates/cast)
2[![crates.io](https://img.shields.io/crates/v/cast.svg)](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