Trait UpcastMul

Source
pub trait UpcastMul<H: Mul<Output = H> + Rem<Output = H>>:
    Upcast<Higher = H>
    + CheckedMul
    + Rem<Output = Self>
    + Copy {
    // Provided methods
    fn upcast_mul(self, rhs: Self) -> H { ... }
    fn upcast_mul_mod(self, rhs: Self, modulo: Self) -> Self { ... }
}
Expand description

Trait to implement upcast mul. (Casting up when type bounds are hit during arithmetic)

Provided Methods§

Source

fn upcast_mul(self, rhs: Self) -> H

performs the operation self * rhs and returns a value of type H.

let a = u8::MAX;
let b = 2;

let expected = u8::MAX as u16 * 2;

let res = a.upcast_mul(b);
assert_eq!(res, expected);
Source

fn upcast_mul_mod(self, rhs: Self, modulo: Self) -> Self

performs the operation (self * rhs) % modulo and returns the a value of type Self.

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.

Implementations on Foreign Types§

Source§

impl UpcastMul<i16> for i8

Source§

impl UpcastMul<i32> for i16

Source§

impl UpcastMul<i64> for i32

Source§

impl UpcastMul<i128> for i64

Source§

impl UpcastMul<u16> for u8

Source§

impl UpcastMul<u32> for u16

Source§

impl UpcastMul<u64> for u32

Source§

impl UpcastMul<u128> for u64

Implementors§