# Trait rocket::mtls::oid::asn1_rs::nom::lib::std::ops::Mul

1.0.0 · source ·
``````pub trait Mul<Rhs = Self> {
type Output;

// Required method
fn mul(self, rhs: Rhs) -> Self::Output;
}``````
Available on crate feature `mtls` only.
Expand description

The multiplication operator `*`.

Note that `Rhs` is `Self` by default, but this is not mandatory.

## §Examples

### §`Mul`tipliable rational numbers

``````use std::ops::Mul;

// By the fundamental theorem of arithmetic, rational numbers in lowest
// terms are unique. So, by keeping `Rational`s in reduced form, we can
// derive `Eq` and `PartialEq`.
#[derive(Debug, Eq, PartialEq)]
struct Rational {
numerator: usize,
denominator: usize,
}

impl Rational {
fn new(numerator: usize, denominator: usize) -> Self {
if denominator == 0 {
panic!("Zero is an invalid denominator!");
}

// Reduce to lowest terms by dividing by the greatest common
// divisor.
let gcd = gcd(numerator, denominator);
Self {
numerator: numerator / gcd,
denominator: denominator / gcd,
}
}
}

impl Mul for Rational {
// The multiplication of rational numbers is a closed operation.
type Output = Self;

fn mul(self, rhs: Self) -> Self {
let numerator = self.numerator * rhs.numerator;
let denominator = self.denominator * rhs.denominator;
Self::new(numerator, denominator)
}
}

// Euclid's two-thousand-year-old algorithm for finding the greatest common
// divisor.
fn gcd(x: usize, y: usize) -> usize {
let mut x = x;
let mut y = y;
while y != 0 {
let t = y;
y = x % y;
x = t;
}
x
}

assert_eq!(Rational::new(1, 2), Rational::new(2, 4));
assert_eq!(Rational::new(2, 3) * Rational::new(3, 4),
Rational::new(1, 2));``````

### §Multiplying vectors by scalars as in linear algebra

``````use std::ops::Mul;

struct Scalar { value: usize }

#[derive(Debug, PartialEq)]
struct Vector { value: Vec<usize> }

impl Mul<Scalar> for Vector {
type Output = Self;

fn mul(self, rhs: Scalar) -> Self::Output {
Self { value: self.value.iter().map(|v| v * rhs.value).collect() }
}
}

let vector = Vector { value: vec![2, 4, 6] };
let scalar = Scalar { value: 3 };
assert_eq!(vector * scalar, Vector { value: vec![6, 12, 18] });``````

## Required Associated Types§

1.0.0 · source

#### type Output

The resulting type after applying the `*` operator.

## Required Methods§

1.0.0 · source

#### fn mul(self, rhs: Rhs) -> Self::Output

Performs the `*` operation.

##### §Example
``assert_eq!(12 * 2, 24);``

## Implementors§

source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

source§

§

source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

source§

§

1.0.0 · source§

§

source§

§

1.0.0 · source§

§

source§

§

1.0.0 · source§

§

source§

§

1.0.0 · source§

§

source§

§

1.0.0 · source§

§

source§

§

1.0.0 · source§

§

source§

§

1.0.0 · source§

§

source§

§

1.0.0 · source§

§

source§

§

1.0.0 · source§

§

source§

§

1.0.0 · source§

§

source§

§

1.0.0 · source§

§

source§

§

1.0.0 · source§

§

source§

§

source§

§

1.0.0 · source§

§

source§

§

source§

§

1.0.0 · source§

§

source§

§

source§

§

1.0.0 · source§

§

source§

§

source§

§

1.0.0 · source§

§

source§

§

source§

§

1.0.0 · source§

§

source§

§

source§

§

1.0.0 · source§

§

source§

§

source§

§

1.0.0 · source§

§

source§

§

source§

§

1.0.0 · source§

§

source§

§

source§

§

1.0.0 · source§

§

source§

§

source§

§

1.0.0 · source§

§

source§

§

source§

§

1.0.0 · source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

1.3.0 · source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

1.31.0 · source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

### impl Mul<B0> for UTerm

`UTerm * B0 = UTerm`

§

source§

### impl Mul<B1> for UTerm

`UTerm * B1 = UTerm`

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.0.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.74.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

1.14.0 · source§

§

source§

§

source§

### impl<I> Mul<I> for Z0where I: Integer,

`Z0 * I = Z0`

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

### impl<U> Mul<Z0> for NInt<U>where U: Unsigned + NonZero,

`N * Z0 = Z0`

§

source§

### impl<U> Mul<Z0> for PInt<U>where U: Unsigned + NonZero,

`P * Z0 = Z0`

§

source§

### impl<U> Mul<U> for UTermwhere U: Unsigned,

`UTerm * U = UTerm`

§

source§

### impl<U, B> Mul<B0> for UInt<U, B>where U: Unsigned, B: Bit,

`UInt * B0 = UTerm`

§

source§

### impl<U, B> Mul<B1> for UInt<U, B>where U: Unsigned, B: Bit,

`UInt * B1 = UInt`

§

source§

### impl<U, B> Mul<UTerm> for UInt<U, B>where U: Unsigned, B: Bit,

`UInt<U, B> * UTerm = UTerm`

§

source§

### impl<Ul, B, Ur> Mul<UInt<Ur, B>> for UInt<Ul, B0>where Ul: Unsigned + Mul<UInt<Ur, B>>, B: Bit, Ur: Unsigned,

`UInt<Ul, B0> * UInt<Ur, B> = UInt<(Ul * UInt<Ur, B>), B0>`

§

source§

### impl<Ul, B, Ur> Mul<UInt<Ur, B>> for UInt<Ul, B1>where Ul: Unsigned + Mul<UInt<Ur, B>>, B: Bit, Ur: Unsigned, UInt<<Ul as Mul<UInt<Ur, B>>>::Output, B0>: Add<UInt<Ur, B>>,

`UInt<Ul, B1> * UInt<Ur, B> = UInt<(Ul * UInt<Ur, B>), B0> + UInt<Ur, B>`

§

source§

### impl<Ul, Ur> Mul<NInt<Ur>> for NInt<Ul>where Ul: Unsigned + NonZero + Mul<Ur>, Ur: Unsigned + NonZero, <Ul as Mul<Ur>>::Output: Unsigned + NonZero,

N(Ul) * N(Ur) = P(Ul * Ur)

§

source§

### impl<Ul, Ur> Mul<NInt<Ur>> for PInt<Ul>where Ul: Unsigned + NonZero + Mul<Ur>, Ur: Unsigned + NonZero, <Ul as Mul<Ur>>::Output: Unsigned + NonZero,

P(Ul) * N(Ur) = N(Ul * Ur)

§

source§

### impl<Ul, Ur> Mul<PInt<Ur>> for NInt<Ul>where Ul: Unsigned + NonZero + Mul<Ur>, Ur: Unsigned + NonZero, <Ul as Mul<Ur>>::Output: Unsigned + NonZero,

N(Ul) * P(Ur) = N(Ul * Ur)

§

source§

### impl<Ul, Ur> Mul<PInt<Ur>> for PInt<Ul>where Ul: Unsigned + NonZero + Mul<Ur>, Ur: Unsigned + NonZero, <Ul as Mul<Ur>>::Output: Unsigned + NonZero,

P(Ul) * P(Ur) = P(Ul * Ur)

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§

source§

§