Multiplicative

Trait Multiplicative 

Source
pub trait Multiplicative:
    Object
    + for<'a> MulAssign<&'a Self>
    + for<'a> Mul<&'a Self, Output = Self> {
    // Provided method
    fn square(&mut self) { ... }
}
Expand description

A type that supports multiplication.

For some type T implementing this trait, the following operations must be supported:

  1. &mut T *= &T,
  2. T * &T.

As with Additive, the borrowing scheme is chosen to keep implementations efficient even for heavier structures.

§Usage


// We use .clone() whenever ownership is needed.
fn example<T: Multiplicative>(mut x: T, y: T) {
    x *= &y;
    x.clone() * &y;
}

Provided Methods§

Source

fn square(&mut self)

Multiply an element with itself.

This has a default implementation involving a clone.

This can be overriden for a specific type that’s better.

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§