pub trait RefShr<Rhs = Self>: Sealed<Rhs> {
type Output;
// Required method
fn ref_shr(&self, rhs: Rhs) -> Self::Output;
}
Expand description
shr
operation through references.
As of Rust 1.73.0, the following code does not compile:
ⓘ
use core::ops::Shr;
struct A<T>(T);
impl<'a, 'b, T, U> Shr<&'b A<U>> for &'a A<T>
where
&'a T: Shr<&'b U>,
{
type Output = A<<&'a T as Shr<&'b U>>::Output>;
fn shr(self, rhs: &'b A<U>) -> Self::Output {
A(self.0.shr(&rhs.0))
}
}
fn _f<T, U>(a: T, b: U)
where
for<'a, 'b> &'a T: Shr<&'b U>,
{
let _a_op_b = (&a).shr(&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: Shr<&'b U>,
{
_f(a, b);
}
but the following code does:
use core::ops::Shr;
use ref_ops::RefShr;
struct A<T>(T);
impl<'a, T, U> Shr<&'a A<U>> for &A<T>
where
T: RefShr<&'a U>,
{
type Output = A<T::Output>;
fn shr(self, rhs: &'a A<U>) -> Self::Output {
A(self.0.ref_shr(&rhs.0))
}
}
fn _f<T, U>(a: T, b: U)
where
for<'a, 'b> &'a T: Shr<&'b U>,
{
let _a_op_b = (&a).shr(&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: Shr<&'b U>,
{
_f(a, b);
}