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 operationAuto Trait Implementations§
impl<'a, T> Freeze for AbelianOperation<'a, T>
impl<'a, T> !RefUnwindSafe for AbelianOperation<'a, T>
impl<'a, T> !Send for AbelianOperation<'a, T>
impl<'a, T> !Sync for AbelianOperation<'a, T>
impl<'a, T> Unpin for AbelianOperation<'a, T>where
T: Unpin,
impl<'a, T> !UnwindSafe for AbelianOperation<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more