Trait ref_ops::RefBitAnd

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

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

bitand operation through references.

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

use core::ops::BitAnd;

struct A<T>(T);

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

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

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

but the following code does:

use core::ops::BitAnd;
use ref_ops::RefBitAnd;

struct A<T>(T);

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

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

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

Required Associated Types§

source

type Output

The resulting type after applying bitand operation.

Required Methods§

source

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

Performs bitand operation.

Implementors§

source§

impl<T, Rhs, O> RefBitAnd<Rhs> for Twhere T: ?Sized, for<'a> &'a T: BitAnd<Rhs, Output = O>,

§

type Output = O