Expand description
An escape hatch for implimenting
Not
for references to structs.
As of Rust 1.64.0, the following code does not compile:
ⓘ
use as_is::ToOwned;
use core::ops::Not;
#[derive(PartialEq)]
struct A<T: ?Sized>(T);
impl<'a, T: ?Sized + ToOwned, O> Not for &'a A<T>
where
    T::Owned: Not<Output = O>,
    &'a T: Not<Output = O>,
{
    type Output = A<O>;
    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`
    todo!();
}
fn _g<T>(a: T)
where
    for<'a> &'a T: Not,
{
    _f(a);
}
assert!(!&A(true) == A(false));but the following code does:
use as_is::ToOwned;
use as_is::ref_ops::RefNot;
use core::ops::Not;
#[derive(PartialEq)]
struct A<T: ?Sized>(T);
impl<T: ?Sized + ToOwned, O> Not for &A<T>
where
    T::Owned: Not<Output = O>,
    T: RefNot<Output = O>,
{
    type Output = A<O>;
    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`
    todo!();
}
fn _g<T>(a: T)
where
    for<'a> &'a T: Not,
{
    _f(a);
}
assert!(!&A(true) == A(false));