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

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

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

The Sub trait is used to specify the functionality of -.

Example

A trivial implementation of Sub. When Foo - Foo happens, it ends up calling sub, and therefore, main prints Subtracting!.

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

#[derive(Copy)]
struct Foo;

impl Sub for Foo {
    type Output = Foo;

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

fn main() {
    Foo - Foo;
}

Associated Types

type Output

Required Methods

fn sub(self, rhs: RHS) -> <Self as Sub<RHS>>::Output

The method for the - operator

Implementors