Trait ref_ops::RefMutShl

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

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

shl operation through mutable references.

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

use core::ops::Shl;

struct A<T>(T);

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

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

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

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

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

but the following code does:

use core::ops::Shl;
use ref_ops::RefMutShl;

struct A<T>(T);

impl<'a, T, U> Shl<&'a mut A<U>> for &mut A<T>
where
    T: RefMutShl<&'a mut U>,
{
    type Output = A<T::Output>;

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

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

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

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

Required Associated Types§

source

type Output

The resulting type after applying shl operation.

Required Methods§

source

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

Performs shl operation.

Implementors§

source§

impl<T, Rhs, O> RefMutShl<Rhs> for Twhere T: ?Sized, for<'a> &'a mut T: Shl<Rhs, Output = O>,

§

type Output = O