Trait RefMutNot

Source
pub trait RefMutNot: Sealed {
    type Output;

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

not operation through mutable 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 mut A<T>
where
    &'a mut T: Not,
{
    type Output = A<<&'a mut T as Not>::Output>;

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

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

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

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

but the following code does:

use core::ops::Not;
use ref_ops::RefMutNot;

struct A<T>(T);


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

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

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

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

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

Required Associated Types§

Source

type Output

The resulting type after applying not operation.

Required Methods§

Source

fn ref_mut_not(&mut self) -> Self::Output

Performs not operation.

Implementors§

Source§

impl<T, O> RefMutNot for T
where T: ?Sized, for<'a> &'a mut T: Not<Output = O>,