Trait core::ops::Add [] [src]

pub trait Add<RHS = Self> {
    type Output;
    fn add(self, rhs: RHS) -> Self::Output;
}

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

Examples

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

use std::ops::Add; #[derive(Copy, Clone)] 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, Clone)]
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

The resulting type after applying the +`+` operator

Required Methods

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

The method for the +`+` operator

Implementors