Trait ref_ops::RefRem

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

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

rem operation through references.

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

use core::ops::Rem;

struct A<T>(T);

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

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

fn _f<T, U>(a: T, b: U)
where
    for<'a, 'b> &'a T: Rem<&'b U>,
{
    let _a_op_b = (&a).rem(&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: Rem<&'b U>,
{
    _f(a, b);
}

but the following code does:

use core::ops::Rem;
use ref_ops::RefRem;

struct A<T>(T);

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

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

fn _f<T, U>(a: T, b: U)
where
    for<'a, 'b> &'a T: Rem<&'b U>,
{
    let _a_op_b = (&a).rem(&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: Rem<&'b U>,
{
    _f(a, b);
}

Required Associated Types§

source

type Output

The resulting type after applying rem operation.

Required Methods§

source

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

Performs rem operation.

Implementors§

source§

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

§

type Output = O