commit | f7708e1e2855aa778b3e35f3bccb8c632c2d5424 | [log] [tgz] |
---|---|---|
author | Linux Build Service Account <lnxbuild@localhost> | Wed Feb 16 21:38:21 2022 -0800 |
committer | Linux Build Service Account <lnxbuild@localhost> | Wed Feb 16 21:38:21 2022 -0800 |
tree | 8a1df24ff4549f3ff836f4b7f89f4bbeff716fc4 | |
parent | 7b2e586ad924ebf153b127a7d700a5e84fdfb26f [diff] | |
parent | 59e3f544253c75f010670f2fa22bd77b2bd6559d [diff] |
Merge 59e3f544253c75f010670f2fa22bd77b2bd6559d on remote branch Change-Id: I7dd77ff160ac4f5297b555d9b4c219cea2b010bc
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.