Trait std::ops::NegStable [-]  [+] [src]

pub trait Neg {
    type Output;
    fn neg(self) -> <Self as Neg>::Output;
}

The Neg trait is used to specify the functionality of unary -.

Example

A trivial implementation of Neg. When -Foo happens, it ends up calling neg, and therefore, main prints Negating!.

#![feature(associated_types)] use std::ops::Neg; struct Foo; impl Copy for Foo {} impl Neg for Foo { type Output = Foo; fn neg(self) -> Foo { println!("Negating!"); self } } fn main() { -Foo; }
#![feature(associated_types)]

use std::ops::Neg;

struct Foo;

impl Copy for Foo {}

impl Neg for Foo {
    type Output = Foo;

    fn neg(self) -> Foo {
        println!("Negating!");
        self
    }
}

fn main() {
    -Foo;
}

Required Methods

type Output

fn neg(self) -> <Self as Neg>::Output

The method for the unary - operator

Implementors