Trait Additive

Source
pub trait Additive {
    // Required methods
    fn add(a: &Self, b: &Self) -> Self;
    fn sub(a: &Self, b: &Self) -> Self;
    fn negate(x: &Self) -> Self;

    // Provided method
    fn double(x: &Self) -> Self
       where Self: Sized { ... }
}
Expand description

Type for which addition is defined

Required Methods§

Source

fn add(a: &Self, b: &Self) -> Self

Computes a + b

Source

fn sub(a: &Self, b: &Self) -> Self

Computes a - b

Source

fn negate(x: &Self) -> Self

Computes -a

Provided Methods§

Source

fn double(x: &Self) -> Self
where Self: Sized,

Takes x, returns x + x

This can be more efficient than calling Self::add(x, x)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§