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§

source

fn new(carrier: GasCarrier) -> Self

Project a value into the gas algebra.

source

fn get(&self) -> GasCarrier

Get the carrier.

Provided Methods§

source

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

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

source

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.

source

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.

source

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.

source

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

Add the two GasAlgebras together.

source

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

Subtract one GasAlgebra from the other.

source

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

Multiply two GasAlgebras together.

source

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

Divide one GasAlgebra by the other.

Implementors§