Trait std::ops::SubAssign [] [src]

pub trait SubAssign<Rhs = Self> {
    fn sub_assign(&mut self, Rhs);
}
Unstable (op_assign_traits #28235)

: recently added

The SubAssign trait is used to specify the functionality of -=.

Examples

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

#![feature(augmented_assignments)] #![feature(op_assign_traits)] use std::ops::SubAssign; #[derive(Copy, Clone)] struct Foo; impl SubAssign for Foo { fn sub_assign(&mut self, _rhs: Foo) { println!("Subtracting!"); } } #[allow(unused_assignments)] fn main() { let mut foo = Foo; foo -= Foo; }
#![feature(augmented_assignments)]
#![feature(op_assign_traits)]

use std::ops::SubAssign;

#[derive(Copy, Clone)]
struct Foo;

impl SubAssign for Foo {
    fn sub_assign(&mut self, _rhs: Foo) {
        println!("Subtracting!");
    }
}

fn main() {
    let mut foo = Foo;
    foo -= Foo;
}

Required Methods

fn sub_assign(&mut self, Rhs)

Unstable (op_assign_traits #28235)

: recently added

The method for the -= operator

Implementors