Trait ref_ops::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.72.1, the following code does not compile:

use core::ops::Not;

struct A<T>(T);

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

    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 Twhere T: ?Sized, for<'a> &'a mut T: Not<Output = O>,

§

type Output = O