pub trait Additive:
Object
+ for<'a> AddAssign<&'a Self>
+ for<'a> Add<&'a Self, Output = Self>
+ for<'a> SubAssign<&'a Self>
+ for<'a> Sub<&'a Self, Output = Self>
+ Neg<Output = Self> {
// Required method
fn zero() -> Self;
// Provided methods
fn double(&mut self) { ... }
fn scale(&self, bits_le: &[u64]) -> Self { ... }
}Expand description
A type that supports addition, subtraction, and negation.
For some type T implementing this trait, the following operations must be
supported:
&mut T += &T,T + &T,&mut T -= &T,T - &T,-T.
There are other combinations of borrowing that could be chosen, but these should be efficiently implementable, even for a “heavier” struct, e.g. a vector of values.
§Usage
// We use .clone() whenever ownership is needed.
fn example<T: Additive>(mut x: T, y: T) {
x += &y;
x.clone() + &y;
x -= &y;
x.clone() - &y;
-x.clone();
T::zero();
}Required Methods§
Provided Methods§
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.