UpcastPow

Trait UpcastPow 

Source
pub trait UpcastPow<H>:
    Upcast<Higher = H>
    + CheckedPow
    + Copy
    + Rem<Output = Self>
where H: Pow + One + PartialOrd + Rem<Output = H> + MulAssign + Copy,
{ // Provided methods fn upcast_pow(self, exp: u32) -> H { ... } fn upcast_pow_mod(self, exp: u32, modulo: Self) -> Self { ... } }
Expand description

Trait to perform upcast pow. (Casting up when type bounds are hit during arithmetic)

§Why the additional bounds?

The algorithm to perform (self % rhs) % modulo is not as straightforward as the other algorithms. The reason behind this is a more complex algorithm used to calculate (self * rhs) % modulo.

Provided Methods§

Source

fn upcast_pow(self, exp: u32) -> H

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

Source

fn upcast_pow_mod(self, exp: u32, modulo: Self) -> Self

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

The implementation uses the Right-to-left binary method.

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 UpcastPow<i16> for i8

Source§

impl UpcastPow<i32> for i16

Source§

impl UpcastPow<i64> for i32

Source§

impl UpcastPow<i128> for i64

Source§

impl UpcastPow<u16> for u8

Source§

impl UpcastPow<u32> for u16

Source§

impl UpcastPow<u64> for u32

Source§

impl UpcastPow<u128> for u64

Implementors§