commit | 738c5d53393504042871aa2d07fc540b03e160a6 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Fri Oct 15 01:05:33 2021 +0000 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Fri Oct 15 01:05:33 2021 +0000 |
tree | 269a30935e7b77960ca42474e69256d37c326058 | |
parent | c9dc5fd3bd844fa88b2fc12e38ba3f12277ceea4 [diff] | |
parent | 6435e04b02e90d3653f5b9e66f44fa3fae00f3e6 [diff] |
Snap for 7825444 from 6435e04b02e90d3653f5b9e66f44fa3fae00f3e6 to tm-release Change-Id: I4753df358f9c69ff3724014e9bf7384777b9eff7
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));
Licensed under either of
at your option.
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.