Trait elliptic_curve::ops::Mul
1.0.0 · source · [−]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
Required Methods
Implementors
sourceimpl Mul<&Saturating<i8>> for &Saturating<i8>
impl Mul<&Saturating<i8>> for &Saturating<i8>
type Output = <Saturating<i8> as Mul<Saturating<i8>>>::Output
sourceimpl Mul<&Saturating<i8>> for Saturating<i8>
impl Mul<&Saturating<i8>> for Saturating<i8>
type Output = <Saturating<i8> as Mul<Saturating<i8>>>::Output
sourceimpl Mul<&Saturating<i16>> for &Saturating<i16>
impl Mul<&Saturating<i16>> for &Saturating<i16>
type Output = <Saturating<i16> as Mul<Saturating<i16>>>::Output
sourceimpl Mul<&Saturating<i16>> for Saturating<i16>
impl Mul<&Saturating<i16>> for Saturating<i16>
type Output = <Saturating<i16> as Mul<Saturating<i16>>>::Output
sourceimpl Mul<&Saturating<i32>> for &Saturating<i32>
impl Mul<&Saturating<i32>> for &Saturating<i32>
type Output = <Saturating<i32> as Mul<Saturating<i32>>>::Output
sourceimpl Mul<&Saturating<i32>> for Saturating<i32>
impl Mul<&Saturating<i32>> for Saturating<i32>
type Output = <Saturating<i32> as Mul<Saturating<i32>>>::Output
sourceimpl Mul<&Saturating<i64>> for &Saturating<i64>
impl Mul<&Saturating<i64>> for &Saturating<i64>
type Output = <Saturating<i64> as Mul<Saturating<i64>>>::Output
sourceimpl Mul<&Saturating<i64>> for Saturating<i64>
impl Mul<&Saturating<i64>> for Saturating<i64>
type Output = <Saturating<i64> as Mul<Saturating<i64>>>::Output
sourceimpl Mul<&Saturating<i128>> for &Saturating<i128>
impl Mul<&Saturating<i128>> for &Saturating<i128>
type Output = <Saturating<i128> as Mul<Saturating<i128>>>::Output
sourceimpl Mul<&Saturating<i128>> for Saturating<i128>
impl Mul<&Saturating<i128>> for Saturating<i128>
type Output = <Saturating<i128> as Mul<Saturating<i128>>>::Output
sourceimpl Mul<&Saturating<isize>> for &Saturating<isize>
impl Mul<&Saturating<isize>> for &Saturating<isize>
type Output = <Saturating<isize> as Mul<Saturating<isize>>>::Output
sourceimpl Mul<&Saturating<isize>> for Saturating<isize>
impl Mul<&Saturating<isize>> for Saturating<isize>
type Output = <Saturating<isize> as Mul<Saturating<isize>>>::Output
sourceimpl Mul<&Saturating<u8>> for &Saturating<u8>
impl Mul<&Saturating<u8>> for &Saturating<u8>
type Output = <Saturating<u8> as Mul<Saturating<u8>>>::Output
sourceimpl Mul<&Saturating<u8>> for Saturating<u8>
impl Mul<&Saturating<u8>> for Saturating<u8>
type Output = <Saturating<u8> as Mul<Saturating<u8>>>::Output
sourceimpl Mul<&Saturating<u16>> for &Saturating<u16>
impl Mul<&Saturating<u16>> for &Saturating<u16>
type Output = <Saturating<u16> as Mul<Saturating<u16>>>::Output
sourceimpl Mul<&Saturating<u16>> for Saturating<u16>
impl Mul<&Saturating<u16>> for Saturating<u16>
type Output = <Saturating<u16> as Mul<Saturating<u16>>>::Output
sourceimpl Mul<&Saturating<u32>> for &Saturating<u32>
impl Mul<&Saturating<u32>> for &Saturating<u32>
type Output = <Saturating<u32> as Mul<Saturating<u32>>>::Output
sourceimpl Mul<&Saturating<u32>> for Saturating<u32>
impl Mul<&Saturating<u32>> for Saturating<u32>
type Output = <Saturating<u32> as Mul<Saturating<u32>>>::Output
sourceimpl Mul<&Saturating<u64>> for &Saturating<u64>
impl Mul<&Saturating<u64>> for &Saturating<u64>
type Output = <Saturating<u64> as Mul<Saturating<u64>>>::Output
sourceimpl Mul<&Saturating<u64>> for Saturating<u64>
impl Mul<&Saturating<u64>> for Saturating<u64>
type Output = <Saturating<u64> as Mul<Saturating<u64>>>::Output
sourceimpl Mul<&Saturating<u128>> for &Saturating<u128>
impl Mul<&Saturating<u128>> for &Saturating<u128>
type Output = <Saturating<u128> as Mul<Saturating<u128>>>::Output
sourceimpl Mul<&Saturating<u128>> for Saturating<u128>
impl Mul<&Saturating<u128>> for Saturating<u128>
type Output = <Saturating<u128> as Mul<Saturating<u128>>>::Output
sourceimpl Mul<&Saturating<usize>> for &Saturating<usize>
impl Mul<&Saturating<usize>> for &Saturating<usize>
type Output = <Saturating<usize> as Mul<Saturating<usize>>>::Output
sourceimpl Mul<&Saturating<usize>> for Saturating<usize>
impl Mul<&Saturating<usize>> for Saturating<usize>
type Output = <Saturating<usize> as Mul<Saturating<usize>>>::Output
sourceimpl Mul<Saturating<i8>> for Saturating<i8>
impl Mul<Saturating<i8>> for Saturating<i8>
type Output = Saturating<i8>
sourceimpl Mul<Saturating<i16>> for Saturating<i16>
impl Mul<Saturating<i16>> for Saturating<i16>
type Output = Saturating<i16>
sourceimpl Mul<Saturating<i32>> for Saturating<i32>
impl Mul<Saturating<i32>> for Saturating<i32>
type Output = Saturating<i32>
sourceimpl Mul<Saturating<i64>> for Saturating<i64>
impl Mul<Saturating<i64>> for Saturating<i64>
type Output = Saturating<i64>
sourceimpl Mul<Saturating<i128>> for Saturating<i128>
impl Mul<Saturating<i128>> for Saturating<i128>
type Output = Saturating<i128>
sourceimpl Mul<Saturating<isize>> for Saturating<isize>
impl Mul<Saturating<isize>> for Saturating<isize>
type Output = Saturating<isize>
sourceimpl Mul<Saturating<u8>> for Saturating<u8>
impl Mul<Saturating<u8>> for Saturating<u8>
type Output = Saturating<u8>
sourceimpl Mul<Saturating<u16>> for Saturating<u16>
impl Mul<Saturating<u16>> for Saturating<u16>
type Output = Saturating<u16>
sourceimpl Mul<Saturating<u32>> for Saturating<u32>
impl Mul<Saturating<u32>> for Saturating<u32>
type Output = Saturating<u32>
sourceimpl Mul<Saturating<u64>> for Saturating<u64>
impl Mul<Saturating<u64>> for Saturating<u64>
type Output = Saturating<u64>
sourceimpl Mul<Saturating<u128>> for Saturating<u128>
impl Mul<Saturating<u128>> for Saturating<u128>
type Output = Saturating<u128>
sourceimpl Mul<Saturating<usize>> for Saturating<usize>
impl Mul<Saturating<usize>> for Saturating<usize>
type Output = Saturating<usize>
sourceimpl<'a> Mul<Saturating<i8>> for &'a Saturating<i8>
impl<'a> Mul<Saturating<i8>> for &'a Saturating<i8>
type Output = <Saturating<i8> as Mul<Saturating<i8>>>::Output
sourceimpl<'a> Mul<Saturating<i16>> for &'a Saturating<i16>
impl<'a> Mul<Saturating<i16>> for &'a Saturating<i16>
type Output = <Saturating<i16> as Mul<Saturating<i16>>>::Output
sourceimpl<'a> Mul<Saturating<i32>> for &'a Saturating<i32>
impl<'a> Mul<Saturating<i32>> for &'a Saturating<i32>
type Output = <Saturating<i32> as Mul<Saturating<i32>>>::Output
sourceimpl<'a> Mul<Saturating<i64>> for &'a Saturating<i64>
impl<'a> Mul<Saturating<i64>> for &'a Saturating<i64>
type Output = <Saturating<i64> as Mul<Saturating<i64>>>::Output
sourceimpl<'a> Mul<Saturating<i128>> for &'a Saturating<i128>
impl<'a> Mul<Saturating<i128>> for &'a Saturating<i128>
type Output = <Saturating<i128> as Mul<Saturating<i128>>>::Output
sourceimpl<'a> Mul<Saturating<isize>> for &'a Saturating<isize>
impl<'a> Mul<Saturating<isize>> for &'a Saturating<isize>
type Output = <Saturating<isize> as Mul<Saturating<isize>>>::Output
sourceimpl<'a> Mul<Saturating<u8>> for &'a Saturating<u8>
impl<'a> Mul<Saturating<u8>> for &'a Saturating<u8>
type Output = <Saturating<u8> as Mul<Saturating<u8>>>::Output
sourceimpl<'a> Mul<Saturating<u16>> for &'a Saturating<u16>
impl<'a> Mul<Saturating<u16>> for &'a Saturating<u16>
type Output = <Saturating<u16> as Mul<Saturating<u16>>>::Output
sourceimpl<'a> Mul<Saturating<u32>> for &'a Saturating<u32>
impl<'a> Mul<Saturating<u32>> for &'a Saturating<u32>
type Output = <Saturating<u32> as Mul<Saturating<u32>>>::Output
sourceimpl<'a> Mul<Saturating<u64>> for &'a Saturating<u64>
impl<'a> Mul<Saturating<u64>> for &'a Saturating<u64>
type Output = <Saturating<u64> as Mul<Saturating<u64>>>::Output
sourceimpl<'a> Mul<Saturating<u128>> for &'a Saturating<u128>
impl<'a> Mul<Saturating<u128>> for &'a Saturating<u128>
type Output = <Saturating<u128> as Mul<Saturating<u128>>>::Output
sourceimpl<'a> Mul<Saturating<usize>> for &'a Saturating<usize>
impl<'a> Mul<Saturating<usize>> for &'a Saturating<usize>
type Output = <Saturating<usize> as Mul<Saturating<usize>>>::Output
sourceimpl<'lhs, 'rhs, T, const LANES: usize> Mul<&'rhs Simd<T, LANES>> for &'lhs Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Mul<Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Mul<Simd<T, LANES>>>::Output == Simd<T, LANES>,
impl<'lhs, 'rhs, T, const LANES: usize> Mul<&'rhs Simd<T, LANES>> for &'lhs Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Mul<Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Mul<Simd<T, LANES>>>::Output == Simd<T, LANES>,
sourceimpl<C> Mul<&NonZeroScalar<C>> for NonZeroScalar<C> where
C: PrimeCurve + ScalarArithmetic,
impl<C> Mul<&NonZeroScalar<C>> for NonZeroScalar<C> where
C: PrimeCurve + ScalarArithmetic,
type Output = NonZeroScalar<C>
sourceimpl<C> Mul<NonZeroScalar<C>> for NonZeroScalar<C> where
C: PrimeCurve + ScalarArithmetic,
impl<C> Mul<NonZeroScalar<C>> for NonZeroScalar<C> where
C: PrimeCurve + ScalarArithmetic,
type Output = NonZeroScalar<C>
sourceimpl<T, const LANES: usize> Mul<&Simd<T, LANES>> for Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Mul<Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Mul<Simd<T, LANES>>>::Output == Simd<T, LANES>,
impl<T, const LANES: usize> Mul<&Simd<T, LANES>> for Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Mul<Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Mul<Simd<T, LANES>>>::Output == Simd<T, LANES>,
sourceimpl<T, const LANES: usize> Mul<Simd<T, LANES>> for &Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Mul<Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Mul<Simd<T, LANES>>>::Output == Simd<T, LANES>,
impl<T, const LANES: usize> Mul<Simd<T, LANES>> for &Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Mul<Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Mul<Simd<T, LANES>>>::Output == Simd<T, LANES>,
sourceimpl<Ul, B, Ur> Mul<UInt<Ur, B>> for UInt<Ul, B0> where
Ul: Unsigned + Mul<UInt<Ur, B>>,
B: Bit,
Ur: Unsigned,
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>
sourceimpl<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>>,
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>
sourceimpl<Ul, Ur> Mul<NInt<Ur>> for NInt<Ul> where
Ul: Unsigned + NonZero + Mul<Ur>,
Ur: Unsigned + NonZero,
<Ul as Mul<Ur>>::Output: Unsigned,
<Ul as Mul<Ur>>::Output: NonZero,
impl<Ul, Ur> Mul<NInt<Ur>> for NInt<Ul> where
Ul: Unsigned + NonZero + Mul<Ur>,
Ur: Unsigned + NonZero,
<Ul as Mul<Ur>>::Output: Unsigned,
<Ul as Mul<Ur>>::Output: NonZero,
N(Ul) * N(Ur) = P(Ul * Ur)
sourceimpl<Ul, Ur> Mul<NInt<Ur>> for PInt<Ul> where
Ul: Unsigned + NonZero + Mul<Ur>,
Ur: Unsigned + NonZero,
<Ul as Mul<Ur>>::Output: Unsigned,
<Ul as Mul<Ur>>::Output: NonZero,
impl<Ul, Ur> Mul<NInt<Ur>> for PInt<Ul> where
Ul: Unsigned + NonZero + Mul<Ur>,
Ur: Unsigned + NonZero,
<Ul as Mul<Ur>>::Output: Unsigned,
<Ul as Mul<Ur>>::Output: NonZero,
P(Ul) * N(Ur) = N(Ul * Ur)
sourceimpl<Ul, Ur> Mul<PInt<Ur>> for NInt<Ul> where
Ul: Unsigned + NonZero + Mul<Ur>,
Ur: Unsigned + NonZero,
<Ul as Mul<Ur>>::Output: Unsigned,
<Ul as Mul<Ur>>::Output: NonZero,
impl<Ul, Ur> Mul<PInt<Ur>> for NInt<Ul> where
Ul: Unsigned + NonZero + Mul<Ur>,
Ur: Unsigned + NonZero,
<Ul as Mul<Ur>>::Output: Unsigned,
<Ul as Mul<Ur>>::Output: NonZero,
N(Ul) * P(Ur) = N(Ul * Ur)
sourceimpl<Ul, Ur> Mul<PInt<Ur>> for PInt<Ul> where
Ul: Unsigned + NonZero + Mul<Ur>,
Ur: Unsigned + NonZero,
<Ul as Mul<Ur>>::Output: Unsigned,
<Ul as Mul<Ur>>::Output: NonZero,
impl<Ul, Ur> Mul<PInt<Ur>> for PInt<Ul> where
Ul: Unsigned + NonZero + Mul<Ur>,
Ur: Unsigned + NonZero,
<Ul as Mul<Ur>>::Output: Unsigned,
<Ul as Mul<Ur>>::Output: NonZero,
P(Ul) * P(Ur) = P(Ul * Ur)