Trait move_core_types::gas_schedule::GasAlgebra
source · pub trait GasAlgebra<GasCarrier>: Sizedwhere
GasCarrier: Add<Output = GasCarrier> + Sub<Output = GasCarrier> + Div<Output = GasCarrier> + Mul<Output = GasCarrier> + Copy,{
// Required methods
fn new(carrier: GasCarrier) -> Self;
fn get(&self) -> GasCarrier;
// Provided methods
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§
Provided Methods§
sourcefn map<F: Fn(GasCarrier) -> GasCarrier>(self, f: F) -> Self
fn map<F: Fn(GasCarrier) -> GasCarrier>(self, f: F) -> Self
Map a function f
of one argument over the underlying data.
sourcefn map2<F: Fn(GasCarrier, GasCarrier) -> GasCarrier>(
self,
other: impl GasAlgebra<GasCarrier>,
f: F
) -> Self
fn map2<F: Fn(GasCarrier, GasCarrier) -> GasCarrier>( self, other: impl GasAlgebra<GasCarrier>, f: F ) -> Self
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.
sourcefn app<T, F: Fn(GasCarrier, GasCarrier) -> T>(
&self,
other: &impl GasAlgebra<GasCarrier>,
f: F
) -> T
fn app<T, F: Fn(GasCarrier, GasCarrier) -> T>( &self, other: &impl GasAlgebra<GasCarrier>, f: F ) -> T
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.
sourcefn unitary_cast<T: GasAlgebra<GasCarrier>>(self) -> T
fn unitary_cast<T: GasAlgebra<GasCarrier>>(self) -> T
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.
sourcefn add(self, right: impl GasAlgebra<GasCarrier>) -> Self
fn add(self, right: impl GasAlgebra<GasCarrier>) -> Self
Add the two GasAlgebra
s together.
sourcefn sub(self, right: impl GasAlgebra<GasCarrier>) -> Self
fn sub(self, right: impl GasAlgebra<GasCarrier>) -> Self
Subtract one GasAlgebra
from the other.
sourcefn mul(self, right: impl GasAlgebra<GasCarrier>) -> Self
fn mul(self, right: impl GasAlgebra<GasCarrier>) -> Self
Multiply two GasAlgebra
s together.
sourcefn div(self, right: impl GasAlgebra<GasCarrier>) -> Self
fn div(self, right: impl GasAlgebra<GasCarrier>) -> Self
Divide one GasAlgebra
by the other.