pub trait ArithmeticOperationExt {
    // Required methods
    fn arithmetic_op(
        self,
        right: Self,
        operation: ArithmeticOperation
    ) -> Result<Self, Error>
       where Self: Sized;
    fn arithmetic_neg(self) -> Result<Self, Error>
       where Self: Sized;
}
Expand description

Trait for arithmetic operations

Required Methods§

source

fn arithmetic_op( self, right: Self, operation: ArithmeticOperation ) -> Result<Self, Error>
where Self: Sized,

Perform an arithmetic operation on two values If the operation is not supported on the given type, an Error::UnsupportedOperation will be returned

§Examples
use polyvalue::{Value};
use polyvalue::operations::{ArithmeticOperation, ArithmeticOperationExt};

let a = Value::from(1);
let b = Value::from(2);

let result = a.arithmetic_op(b, ArithmeticOperation::Add).unwrap();
assert_eq!(result, Value::from(3));
source

fn arithmetic_neg(self) -> Result<Self, Error>
where Self: Sized,

Perform an arithmetic negation on a value This is equivalent to arithmetic_op with ArithmeticOperation::Negate but is provided for convenience

§Examples
use polyvalue::{Value};
use polyvalue::operations::{ArithmeticOperation, ArithmeticOperationExt};

let a = Value::from(1);
let result = a.arithmetic_neg().unwrap();
assert_eq!(result, Value::from(-1));

Implementors§