Trait ArithmeticOps

Source
pub trait ArithmeticOps {
    // Required methods
    fn add(&self, other: &Self) -> Result<Self, String>
       where Self: Sized;
    fn subtract(&self, other: &Self) -> Result<Self, String>
       where Self: Sized;
    fn multiply(&self, other: &Self) -> Result<Self, String>
       where Self: Sized;
    fn divide(&self, other: &Self) -> Result<Self, String>
       where Self: Sized;
    fn negate(&self) -> Result<Self, String>
       where Self: Sized;
}
Expand description

Arithmetic operations on values

Required Methods§

Source

fn add(&self, other: &Self) -> Result<Self, String>
where Self: Sized,

Adds two values and returns the result.

§Arguments
  • other - The other value to add
§Returns
  • The result of the addition
  • An error message if the types are incompatible
Source

fn subtract(&self, other: &Self) -> Result<Self, String>
where Self: Sized,

Subtracts one value from another and returns the result.

§Arguments
  • other - The value to subtract
§Returns
  • The result of the subtraction
  • An error message if the types are incompatible or if an underflow occurs
Source

fn multiply(&self, other: &Self) -> Result<Self, String>
where Self: Sized,

Multiplies two values and returns the result.

§Arguments
  • other - The other value to multiply
§Returns
  • The result of the multiplication
  • An error message if the types are incompatible or if an overflow occurs
Source

fn divide(&self, other: &Self) -> Result<Self, String>
where Self: Sized,

Divides one value by another and returns the result.

§Arguments
  • other - The value to divide by
§Returns
  • The result of the division
  • An error message if the types are incompatible or if division by zero occurs
Source

fn negate(&self) -> Result<Self, String>
where Self: Sized,

Negates a value and returns the result.

§Returns
  • The negated value
  • An error message if the type is incompatible, or an overflow occurs

Implementors§