| commit | 978d23b48d01747e9977161829f071a2b7e70395 | [log] [tgz] |
|---|---|---|
| author | Android Build Coastguard Worker <[email protected]> | Thu Aug 15 23:11:00 2024 +0000 |
| committer | Android Build Coastguard Worker <[email protected]> | Thu Aug 15 23:11:00 2024 +0000 |
| tree | ffdc4526e3d0d51ce1f669826c39c8e3981ec6dc | |
| parent | 66d5b62fe81d58e9d60a2438711152b89fa98a4c [diff] | |
| parent | 0e0cc8861aa402414fccdb8346b8d2ad5faeea64 [diff] |
Snap for 12235414 from 0e0cc8861aa402414fccdb8346b8d2ad5faeea64 to 24Q4-release Change-Id: I73536fa099428a0d8b06679434eb77ceb286baeb
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.