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

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

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

Examples

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, 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