Trait RefMutBitAnd

Source
pub trait RefMutBitAnd<Rhs = Self>: Sealed<Rhs> {
    type Output;

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

bitand operation through mutable references.

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

use core::ops::BitAnd;

struct A<T>(T);

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

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

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

but the following code does:

use core::ops::BitAnd;
use ref_ops::RefMutBitAnd;

struct A<T>(T);

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

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

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

Required Associated Types§

Source

type Output

The resulting type after applying bitand operation.

Required Methods§

Source

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

Performs bitand operation.

Implementors§

Source§

impl<T, Rhs, O> RefMutBitAnd<Rhs> for T
where T: ?Sized, for<'a> &'a mut T: BitAnd<Rhs, Output = O>,