Macro forward_ref::forward_ref_op_assign[][src]

macro_rules! forward_ref_op_assign {
    (impl $imp:ident, $method:ident for $t:ty, $u:ty) => { ... };
}
Expand description

Extend an assignment operator trait impl over refs.

Given an implementation of T op= U where U is Copyable, implements the binary operator T op= &U.

Examples

use core::ops::AddAssign;
use forward_ref::forward_ref_op_assign;

#[derive(Clone, Copy, Debug, PartialEq)]
struct MyInt(i32);

impl AddAssign for MyInt {
    #[inline]
    fn add_assign(&mut self, rhs: Self) {
        self.0 += rhs.0;
    }
}

forward_ref_op_assign!(impl AddAssign, add_assign for MyInt, MyInt);

// Now addition assignment will also work for references.
let mut a = MyInt(1);
let b = MyInt(2);

a += b;
assert_eq!(a, MyInt(3));

a += &b;
assert_eq!(a, MyInt(5));