Struct algae_rs::mapping::AbelianOperation
source · pub struct AbelianOperation<'a, T> { /* private fields */ }
Expand description
A function wrapper enforcing commutativity.
Examples
let mut add = AbelianOperation::new(&|a, b| {
a + b
});
let sum = add.with(1, 2);
assert!(sum.is_ok());
assert!(sum.unwrap() == 3);
let mut sub = AbelianOperation::new(&|a, b| {
a - b
});
let pos_difference = sub.with(4, 3);
assert!(pos_difference.is_err());
let neg_difference = sub.with(1, 2);
assert!(neg_difference.is_err());
Implementations§
Trait Implementations§
source§impl<'a, T: Copy + PartialEq> BinaryOperation<T> for AbelianOperation<'a, T>
impl<'a, T: Copy + PartialEq> BinaryOperation<T> for AbelianOperation<'a, T>
source§fn operation(&self) -> &dyn Fn(T, T) -> T
fn operation(&self) -> &dyn Fn(T, T) -> T
Returns a reference to the function underlying the operation
source§fn properties(&self) -> Vec<PropertyType<T>>
fn properties(&self) -> Vec<PropertyType<T>>
Vec of all enforced properties
source§fn input_history(&self) -> &Vec<T>
fn input_history(&self) -> &Vec<T>
Returns a reference to a Vec of all previous inputs to the operation
source§fn is(&self, property: PropertyType<T>) -> bool
fn is(&self, property: PropertyType<T>) -> bool
Returns whether or not
property
is enforced by the given operation