pub trait AsU256 {
// Required method
fn as_u256(self) -> U256;
}
Expand description
This trait defines as
conversions (casting) from primitive types to
U256
.
§Examples
Note that in Rust casting from a negative signed integer sign to a larger
unsigned interger sign extends. Additionally casting a floating point value
to an integer is a saturating operation, with NaN
converting to 0
. So:
assert_eq!((-1i32).as_u256(), U256::MAX);
assert_eq!(u32::MAX.as_u256(), 0xffffffff);
assert_eq!(f64::NEG_INFINITY.as_u256(), 0);
assert_eq!((-1.0f64).as_u256(), 0);
assert_eq!(f64::INFINITY.as_u256(), U256::MAX);
assert_eq!(2.0f64.powi(257).as_u256(), U256::MAX);
assert_eq!(f64::NAN.as_u256(), 0);