pub trait GasAlgebra<GasCarrier>: Sizedwhere
    GasCarrier: Add<GasCarrier, Output = GasCarrier> + Sub<GasCarrier, Output = GasCarrier> + Div<GasCarrier, Output = GasCarrier> + Mul<GasCarrier, Output = GasCarrier> + Copy,{
    // Required methods
    fn new(carrier: GasCarrier) -> Self;
    fn get(&self) -> GasCarrier;

    // Provided methods
    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§

fn new(carrier: GasCarrier) -> Self

Project a value into the gas algebra.

fn get(&self) -> GasCarrier

Get the carrier.

Provided Methods§

fn map<F>(self, f: F) -> Selfwhere F: Fn(GasCarrier) -> GasCarrier,

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

fn map2<F>(self, other: impl GasAlgebra<GasCarrier>, f: F) -> Selfwhere 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) -> Twhere 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) -> Twhere 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

Add the two GasAlgebras together.

fn sub(self, right: impl GasAlgebra<GasCarrier>) -> Self

Subtract one GasAlgebra from the other.

fn mul(self, right: impl GasAlgebra<GasCarrier>) -> Self

Multiply two GasAlgebras together.

fn div(self, right: impl GasAlgebra<GasCarrier>) -> Self

Divide one GasAlgebra by the other.

Implementors§