Trait std::ops::Sub[src]

pub trait Sub<RHS, Result> {
    fn sub<RHS, Result>(&self, rhs: &RHS) -> Result;
}

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!.

struct Foo; impl Sub<Foo, Foo> for Foo { fn sub(&self, _rhs: &Foo) -> Foo { println!("Subtracting!"); *self } } fn main() { Foo - Foo; }
struct Foo;

impl Sub<Foo, Foo> for Foo {
    fn sub(&self, _rhs: &Foo) -> Foo {
        println!("Subtracting!");
        *self
    }
}

fn main() {
    Foo - Foo;
}

Required Methods

fn sub<RHS, Result>(&self, rhs: &RHS) -> Result

The method for the - operator

Implementors