Trait std::ops::Sub [] [src]

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

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

Examples

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

use std::ops::Sub; 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;

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

The resulting type after applying the - operator

Required Methods

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

The method for the - operator

Implementors