soroban_env_common::num

Trait AsU256

Source
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);

Required Methods§

Source

fn as_u256(self) -> U256

Perform an as conversion to a U256.

Implementations on Foreign Types§

Source§

impl AsU256 for bool

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for f32

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for f64

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for i8

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for i16

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for i32

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for i64

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for i128

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for isize

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for u8

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for u16

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for u32

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for u64

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for u128

Source§

fn as_u256(self) -> U256

Source§

impl AsU256 for usize

Source§

fn as_u256(self) -> U256

Implementors§