Trait ref_ops::RefMul

source ·
pub trait RefMul<Rhs = Self>: Sealed<Rhs> {
    type Output;

    // Required method
    fn ref_mul(&self, rhs: Rhs) -> Self::Output;
}
Expand description

mul operation through references.

As of Rust 1.73.0, the following code does not compile:

use core::ops::Mul;

struct A<T>(T);

impl<'a, 'b, T, U> Mul<&'b A<U>> for &'a A<T>
where
    &'a T: Mul<&'b U>,
{
    type Output = A<<&'a T as Mul<&'b U>>::Output>;

    fn mul(self, rhs: &'b A<U>) -> Self::Output {
        A(self.0.mul(&rhs.0))
    }
}

fn _f<T, U>(a: T, b: U)
where
    for<'a, 'b> &'a T: Mul<&'b U>,
{
    let _a_op_b = (&a).mul(&b);

    // to do something with `a`, `b`, and `_a_op_b`
}

fn _g<T, U>(a: T, b: U)
where
    for<'a, 'b> &'a T: Mul<&'b U>,
{
    _f(a, b);
}

but the following code does:

use core::ops::Mul;
use ref_ops::RefMul;

struct A<T>(T);

impl<'a, T, U> Mul<&'a A<U>> for &A<T>
where
    T: RefMul<&'a U>,
{
    type Output = A<T::Output>;

    fn mul(self, rhs: &'a A<U>) -> Self::Output {
        A(self.0.ref_mul(&rhs.0))
    }
}

fn _f<T, U>(a: T, b: U)
where
    for<'a, 'b> &'a T: Mul<&'b U>,
{
    let _a_op_b = (&a).mul(&b);

    // to do something with `a`, `b`, and `_a_op_b`
}

fn _g<T, U>(a: T, b: U)
where
    for<'a, 'b> &'a T: Mul<&'b U>,
{
    _f(a, b);
}

Required Associated Types§

source

type Output

The resulting type after applying mul operation.

Required Methods§

source

fn ref_mul(&self, rhs: Rhs) -> Self::Output

Performs mul operation.

Implementors§

source§

impl<T, Rhs, O> RefMul<Rhs> for Twhere T: ?Sized, for<'a> &'a T: Mul<Rhs, Output = O>,

§

type Output = O