• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

ci/23-Nov-2023-5441

src/23-Nov-2023-769513

.cargo_vcs_info.jsonD23-Nov-202374 65

.gitignoreD23-Nov-202328 43

.travis.ymlD23-Nov-2023471 3623

Android.bpD23-Nov-20231.8 KiB5954

CHANGELOG.mdD23-Nov-20231.3 KiB5532

Cargo.tomlD23-Nov-20231 KiB3229

Cargo.toml.origD23-Nov-2023682 2622

LICENSED23-Nov-202310.6 KiB202169

LICENSE-APACHED23-Nov-202310.6 KiB202169

LICENSE-MITD23-Nov-20231 KiB2622

METADATAD23-Nov-2023378 2019

MODULE_LICENSE_APACHE2D23-Nov-20230

OWNERSD23-Nov-202340 21

README.mdD23-Nov-20231.4 KiB4531

build.rsD23-Nov-2023192 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