Trait core::ops::Add[src]

pub trait Add<RHS, Result> {
    fn add(&self, rhs: &RHS) -> Result;
}

The Add trait is used to specify the functionality of +.

Example

A trivial implementation of Add. When Foo + Foo happens, it ends up calling add, and therefore, main prints Adding!.

struct Foo; impl Add<Foo, Foo> for Foo { fn add(&self, _rhs: &Foo) -> Foo { println!("Adding!"); *self } } fn main() { Foo + Foo; }
struct Foo;

impl Add<Foo, Foo> for Foo {
    fn add(&self, _rhs: &Foo) -> Foo {
      println!("Adding!");
      *self
  }
}

fn main() {
  Foo + Foo;
}

Required Methods

fn add(&self, rhs: &RHS) -> Result

The method for the + operator

Implementors