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);
}