pub struct CancellativeOperation<'a, T> { /* private fields */ }
Expand description

A function wrapper enforcing cancellativity.

Examples

use algae_rs::mapping::{CancellativeOperation, BinaryOperation};

let mut mul = CancellativeOperation::new(&|a, b| a * b);

let six = mul.with(2, 3);
assert!(six.is_ok());
assert!(six.unwrap() == 6);

Implementations§

source§

impl<'a, T> CancellativeOperation<'a, T>

source

pub fn new(op: &'a dyn Fn(T, T) -> T) -> Self

Trait Implementations§

source§

impl<'a, T: Copy + PartialEq> BinaryOperation<T> for CancellativeOperation<'a, T>

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
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. Read more

Auto Trait Implementations§

§

impl<'a, T> !RefUnwindSafe for CancellativeOperation<'a, T>

§

impl<'a, T> !Send for CancellativeOperation<'a, T>

§

impl<'a, T> !Sync for CancellativeOperation<'a, T>

§

impl<'a, T> Unpin for CancellativeOperation<'a, T>where
T: Unpin,

§

impl<'a, T> !UnwindSafe for CancellativeOperation<'a, T>

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.