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§
Sourcefn operation(&self) -> &dyn Fn(T, T) -> T
fn operation(&self) -> &dyn Fn(T, T) -> T
Returns a reference to the function underlying the operation
Sourcefn properties(&self) -> Vec<PropertyType<'_, T>>
fn properties(&self) -> Vec<PropertyType<'_, T>>
Vec of all enforced properties
Sourcefn input_history(&self) -> &Vec<T>
fn input_history(&self) -> &Vec<T>
Returns a reference to a Vec of all previous inputs to the operation
Provided Methods§
Sourcefn is(&self, property: PropertyType<'_, T>) -> bool
fn is(&self, property: PropertyType<'_, T>) -> bool
Returns whether or not property
is enforced by the given operation
Sourcefn with(&mut self, left: T, right: T) -> Result<T, PropertyError>
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.