Skip to main content

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.

§Properties

Implementations are expected to have a commutative, associative multiplication:

  • *= agrees with *,
  • multiplication satisfies a * b = b * a and (a * b) * c = a * (b * c).

§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".

Implementors§