Trait CostType

Source
pub trait CostType:
    Sized
    + From<usize>
    + Copy
    + Send
    + Mul<Output = Self>
    + Div<Output = Self>
    + Add<Output = Self>
    + Sub<Output = Self>
    + Shr<usize, Output = Self>
    + Shl<usize, Output = Self>
    + AddAssign
    + SubAssign
    + Ord
    + Debug {
    // Required methods
    fn as_u256(&self) -> U256;
    fn from_u256(val: U256) -> Result<Self>;
    fn as_usize(&self) -> usize;
    fn overflow_add(self, other: Self) -> (Self, bool);
    fn overflow_mul(self, other: Self) -> (Self, bool);
    fn overflow_mul_shr(self, other: Self, shr: usize) -> (Self, bool);
}
Expand description

Cost calculation type. For low-gas usage we calculate costs using usize instead of U256

Required Methods§

Source

fn as_u256(&self) -> U256

Converts this cost into U256

Source

fn from_u256(val: U256) -> Result<Self>

Tries to fit U256 into this Cost type

Source

fn as_usize(&self) -> usize

Convert to usize (may panic)

Source

fn overflow_add(self, other: Self) -> (Self, bool)

Add with overflow

Source

fn overflow_mul(self, other: Self) -> (Self, bool)

Multiple with overflow

Source

fn overflow_mul_shr(self, other: Self, shr: usize) -> (Self, bool)

Single-step full multiplication and shift: (self*other) >> shr Should not overflow on intermediate steps

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl CostType for usize

Source§

fn as_u256(&self) -> U256

Source§

fn from_u256(val: U256) -> Result<Self>

Source§

fn as_usize(&self) -> usize

Source§

fn overflow_add(self, other: Self) -> (Self, bool)

Source§

fn overflow_mul(self, other: Self) -> (Self, bool)

Source§

fn overflow_mul_shr(self, other: Self, shr: usize) -> (Self, bool)

Source§

impl CostType for U256

Source§

fn as_u256(&self) -> U256

Source§

fn from_u256(val: U256) -> Result<Self>

Source§

fn as_usize(&self) -> usize

Source§

fn overflow_add(self, other: Self) -> (Self, bool)

Source§

fn overflow_mul(self, other: Self) -> (Self, bool)

Source§

fn overflow_mul_shr(self, other: Self, shr: usize) -> (Self, bool)

Implementors§