Trait move_core_types::gas_schedule::GasAlgebra[][src]

pub trait GasAlgebra<GasCarrier>: Sized where
    GasCarrier: Add<Output = GasCarrier> + Sub<Output = GasCarrier> + Div<Output = GasCarrier> + Mul<Output = GasCarrier> + Copy
{ fn new(carrier: GasCarrier) -> Self;
fn get(&self) -> GasCarrier; fn map<F: Fn(GasCarrier) -> GasCarrier>(self, f: F) -> Self { ... }
fn map2<F: Fn(GasCarrier, GasCarrier) -> GasCarrier>(
        self,
        other: impl GasAlgebra<GasCarrier>,
        f: F
    ) -> Self { ... }
fn app<T, F: Fn(GasCarrier, GasCarrier) -> T>(
        &self,
        other: &impl GasAlgebra<GasCarrier>,
        f: F
    ) -> T { ... }
fn unitary_cast<T: GasAlgebra<GasCarrier>>(self) -> T { ... }
fn add(self, right: impl GasAlgebra<GasCarrier>) -> Self { ... }
fn sub(self, right: impl GasAlgebra<GasCarrier>) -> Self { ... }
fn mul(self, right: impl GasAlgebra<GasCarrier>) -> Self { ... }
fn div(self, right: impl GasAlgebra<GasCarrier>) -> Self { ... } }
Expand description

A trait encoding the operations permitted on the underlying carrier for the gas unit, and how other gas-related units can interact with other units – operations can only be performed across units with the same underlying carrier (i.e. as long as the underlying data is the same).

Required methods

Project a value into the gas algebra.

Get the carrier.

Provided methods

Map a function f of one argument over the underlying data.

Map a function f of two arguments over the underlying carrier. Note that this function can take two different implementations of the trait – one for self the other for the second argument. But, we enforce that they have the same underlying carrier.

Apply a function f of two arguments to the carrier. Since f is not an endomorphism, we return the resulting value, as opposed to the result wrapped up in ourselves.

We allow casting between GasAlgebras as long as they have the same underlying carrier – i.e. they use the same type to store the underlying value.

Add the two GasAlgebras together.

Subtract one GasAlgebra from the other.

Multiply two GasAlgebras together.

Divide one GasAlgebra by the other.

Implementors