| commit | 568d3118c52481b20541aa8752c95a7456e2f699 | [log] [tgz] |
|---|---|---|
| author | Android Build Coastguard Worker <[email protected]> | Tue May 21 23:12:21 2024 +0000 |
| committer | Android Build Coastguard Worker <[email protected]> | Tue May 21 23:12:21 2024 +0000 |
| tree | 8c99ee87a63e52bc2f27d3097975efc138a4c532 | |
| parent | 1b77af8c61ae4fbab857cfc9e7aa077c75bb694b [diff] | |
| parent | 60ee13c51de4b4e0145cbfb4653321c14847da6b [diff] |
Snap for 11869550 from 60ee13c51de4b4e0145cbfb4653321c14847da6b to 24Q3-release Change-Id: I05ed0b5d39938c8ef0a67fa3c5bf4c09262b8dd7
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.