Trait core::ops::Sub [] [src]

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

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

Examples

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

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