Trait diem_sdk::move_types::gas_schedule::GasAlgebra [−][src]
pub trait GasAlgebra<GasCarrier> where
GasCarrier: Add<GasCarrier, Output = GasCarrier> + Sub<GasCarrier, Output = GasCarrier> + Div<GasCarrier, Output = GasCarrier> + Mul<GasCarrier, Output = GasCarrier> + Copy, {
fn new(carrier: GasCarrier) -> Self;
fn get(&self) -> GasCarrier;
fn map<F>(self, f: F) -> Self
where
F: Fn(GasCarrier) -> GasCarrier,
{ ... }
fn map2<F>(self, other: impl GasAlgebra<GasCarrier>, f: F) -> Self
where
F: Fn(GasCarrier, GasCarrier) -> GasCarrier,
{ ... }
fn app<T, F>(&self, other: &impl GasAlgebra<GasCarrier>, f: F) -> T
where
F: Fn(GasCarrier, GasCarrier) -> T,
{ ... }
fn unitary_cast<T>(self) -> T
where
T: GasAlgebra<GasCarrier>,
{ ... }
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
Map a function f
of one argument over the underlying data.
fn map2<F>(self, other: impl GasAlgebra<GasCarrier>, f: F) -> Self where
F: Fn(GasCarrier, GasCarrier) -> GasCarrier,
fn map2<F>(self, other: impl GasAlgebra<GasCarrier>, f: F) -> Self where
F: Fn(GasCarrier, GasCarrier) -> GasCarrier,
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.
fn app<T, F>(&self, other: &impl GasAlgebra<GasCarrier>, f: F) -> T where
F: Fn(GasCarrier, GasCarrier) -> T,
fn app<T, F>(&self, other: &impl GasAlgebra<GasCarrier>, f: F) -> T where
F: Fn(GasCarrier, GasCarrier) -> 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.
fn unitary_cast<T>(self) -> T where
T: GasAlgebra<GasCarrier>,
fn unitary_cast<T>(self) -> T where
T: GasAlgebra<GasCarrier>,
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.
fn add(self, right: impl GasAlgebra<GasCarrier>) -> Self
fn add(self, right: impl GasAlgebra<GasCarrier>) -> Self
Add the two GasAlgebra
s together.
fn sub(self, right: impl GasAlgebra<GasCarrier>) -> Self
fn sub(self, right: impl GasAlgebra<GasCarrier>) -> Self
Subtract one GasAlgebra
from the other.
fn mul(self, right: impl GasAlgebra<GasCarrier>) -> Self
fn mul(self, right: impl GasAlgebra<GasCarrier>) -> Self
Multiply two GasAlgebra
s together.
fn div(self, right: impl GasAlgebra<GasCarrier>) -> Self
fn div(self, right: impl GasAlgebra<GasCarrier>) -> Self
Divide one GasAlgebra
by the other.