Trait std::ops::AddStable [-] [+] [src]

pub trait Add<RHS = Self> where <Self as Add<RHS>>::Output: Sized {
    type Output;

    fn add(self, rhs: RHS) -> <Self as Add<RHS>>::Output;
}

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!.

use std::ops::Add; #[derive(Copy)] struct Foo; impl Add for Foo { type Output = Foo; fn add(self, _rhs: Foo) -> Foo { println!("Adding!"); self } } fn main() { Foo + Foo; }
use std::ops::Add;

#[derive(Copy)]
struct Foo;

impl Add for Foo {
    type Output = Foo;

    fn add(self, _rhs: Foo) -> Foo {
      println!("Adding!");
      self
  }
}

fn main() {
  Foo + Foo;
}

Associated Types

type Output

Required Methods

fn add(self, rhs: RHS) -> <Self as Add<RHS>>::Output

The method for the + operator

Implementors