Trait BinaryOperation

Source
pub trait BinaryOperation<T: Copy + PartialEq> {
    // Required methods
    fn operation(&self) -> &dyn Fn(T, T) -> T;
    fn properties(&self) -> Vec<PropertyType<'_, T>>;
    fn input_history(&self) -> &Vec<T>;
    fn cache(&mut self, input: T);

    // Provided methods
    fn is(&self, property: PropertyType<'_, T>) -> bool { ... }
    fn with(&mut self, left: T, right: T) -> Result<T, PropertyError> { ... }
}
Expand description

Common interface for all Algae operations.

All operations in Algae implement AlgaeOperation. This trait’s key feature is the provided with method, which provides a common interface both for retrieving the results of binary operations in Algae and for enforcing their specified properties.

Property enforcement is done by keeping a history of all the inputs given to the operation. The property is enforced among all combinations of previous inputs every time the operation is called. The existence of the input history is required by input_history, and the caching mechanism is given by cache. The operation itself is given by a reference to a function via operation.

Required Methods§

Source

fn operation(&self) -> &dyn Fn(T, T) -> T

Returns a reference to the function underlying the operation

Source

fn properties(&self) -> Vec<PropertyType<'_, T>>

Vec of all enforced properties

Source

fn input_history(&self) -> &Vec<T>

Returns a reference to a Vec of all previous inputs to the operation

Source

fn cache(&mut self, input: T)

Caches the given input to the operation’s input history

Provided Methods§

Source

fn is(&self, property: PropertyType<'_, T>) -> bool

Returns whether or not property is enforced by the given operation

Source

fn with(&mut self, left: T, right: T) -> Result<T, PropertyError>

Returns the result of performing the given operation.

If the operation is found not to obey all of its stated properties, an appropriate Err will be returned; if else, an Ok wrapping the proper result of the operation with the given inputs will be returned.

Implementors§