Trait ref_ops::RefNot

source ·
pub trait RefNot: Sealed {
    type Output;

    // Required method
    fn ref_not(&self) -> Self::Output;
}
Expand description

not operation through references.

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

use core::ops::Not;

struct A<T>(T);

impl<'a, T> Not for &'a A<T>
where
    &'a T: Not,
{
    type Output = A<<&'a T as Not>::Output>;

    fn not(self) -> Self::Output {
        A(self.0.not())
    }
}

fn _f<T>(a: T)
where
    for<'a> &'a T: Not,
{
    let _op_a = (&a).not();

    // to do something with `a` and `_op_a`
}

fn _g<T>(a: T)
where
    for<'a> &'a T: Not,
{
    _f(a);
}

but the following code does:

use core::ops::Not;
use ref_ops::RefNot;

struct A<T>(T);


impl<T> Not for &A<T>
where
    T: RefNot,
{
    type Output = A<T::Output>;

    fn not(self) -> Self::Output {
        A(self.0.ref_not())
    }
}

fn _f<T>(a: T)
where
    for<'a> &'a T: Not,
{
    let _op_a = (&a).not();

    // to do something with `a` and `_op_a`
}

fn _g<T>(a: T)
where
    for<'a> &'a T: Not,
{
    _f(a);
}

Required Associated Types§

source

type Output

The resulting type after applying not operation.

Required Methods§

source

fn ref_not(&self) -> Self::Output

Performs not operation.

Implementors§

source§

impl<T, O> RefNot for Twhere T: ?Sized, for<'a> &'a T: Not<Output = O>,

§

type Output = O