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

pub trait Sub<RHS = Self> {
    type Output;

    fn sub(self, rhs: 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!.

#![feature(associated_types)] 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; }
#![feature(associated_types)]

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) -> Output

The method for the - operator

Implementors