Trait ref_ops::RefMutDiv

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

    fn ref_mut_div(&mut self, rhs: Rhs) -> Self::Output;
}
Expand description

div operation through mutable references.

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

use core::ops::Div;

struct A<T>(T);

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

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

fn _f<T, U>(mut a: T, mut b: U)
where
    for<'a, 'b> &'a mut T: Div<&'b mut U>,
{
    let _a_op_b = (&mut a).div(&mut b);

    // to do something with `a`, `b`, and `_a_op_b`
}

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

but the following code does:

use core::ops::Div;
use ref_ops::RefMutDiv;

struct A<T>(T);

impl<'a, T, U> Div<&'a mut A<U>> for &mut A<T>
where
    T: RefMutDiv<&'a mut U>,
{
    type Output = A<T::Output>;

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

fn _f<T, U>(mut a: T, mut b: U)
where
    for<'a, 'b> &'a mut T: Div<&'b mut U>,
{
    let _a_op_b = (&mut a).div(&mut b);

    // to do something with `a`, `b`, and `_a_op_b`
}

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

Required Associated Types

The resulting type after applying div operation.

Required Methods

Performs div operation.

Implementors