pub struct AssociativeOperation<'a, T> { /* private fields */ }
Expand description
A function wrapper enforcing associativity.
§Examples
let mut mul = AssociativeOperation::new(&|a, b| {
a * b
});
let six = mul.with(2, 3);
let twenty = mul.with(4, 5);
assert!(six.is_ok());
assert!(six.unwrap() == 6);
assert!(twenty.is_ok());
assert!(twenty.unwrap() == 20);
let mut div = AssociativeOperation::new(&|a, b| {
a / b
});
let whole_dividend = div.with(4.0, 2.0);
assert!(whole_dividend.is_ok());
assert!(whole_dividend.unwrap() == 2.0);
let fractional_dividend = div.with(3.0, 1.0);
assert!(fractional_dividend.is_err());
Implementations§
Trait Implementations§
Source§impl<'a, T: Copy + PartialEq> BinaryOperation<T> for AssociativeOperation<'a, T>
impl<'a, T: Copy + PartialEq> BinaryOperation<T> for AssociativeOperation<'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 AssociativeOperation<'a, T>
impl<'a, T> !RefUnwindSafe for AssociativeOperation<'a, T>
impl<'a, T> !Send for AssociativeOperation<'a, T>
impl<'a, T> !Sync for AssociativeOperation<'a, T>
impl<'a, T> Unpin for AssociativeOperation<'a, T>where
T: Unpin,
impl<'a, T> !UnwindSafe for AssociativeOperation<'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