| commit | 9e801b7b6e8c534c8e6c135b986a8d879ae93bf4 | [log] [tgz] |
|---|---|---|
| author | Android Build Coastguard Worker <[email protected]> | Tue Sep 10 23:08:42 2024 +0000 |
| committer | Android Build Coastguard Worker <[email protected]> | Tue Sep 10 23:08:42 2024 +0000 |
| tree | ffdc4526e3d0d51ce1f669826c39c8e3981ec6dc | |
| parent | 6061cbb3d83b153a753d18db223eb9ea42af4990 [diff] | |
| parent | c83b0310de8faabd23970489c8a280d59db00204 [diff] |
Snap for 12349386 from c83b0310de8faabd23970489c8a280d59db00204 to sdk-release Change-Id: Ifed90b5b480a6b6e820ab799efd5920a9e34f882
castErgonomic, 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.