Trait collections::std::ops::Neg [] [src]

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

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

Examples

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

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

struct Foo;

impl Neg for Foo {
    type Output = Foo;

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

fn main() {
    -Foo;
}

Associated Types

type Output

The resulting type after applying the - operator

Required Methods

fn neg(self) -> Self::Output

The method for the unary - operator

Implementors