Trait ref_ops::RefMutBitOr

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

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

bitor operation through mutable references.

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

use core::ops::BitOr;

struct A<T>(T);

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

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

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

but the following code does:

use core::ops::BitOr;
use ref_ops::RefMutBitOr;

struct A<T>(T);

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

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

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

Required Associated Types§

source

type Output

The resulting type after applying bitor operation.

Required Methods§

source

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

Performs bitor operation.

Implementors§

source§

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

§

type Output = O