Attribute Macro opimps::impl_op_assign
source · #[impl_op_assign]
Expand description
The direct implementation for assignment-based operators.
pub struct TestObj {
pub val: i32
}
#[opimps::impl_op_assign(std::ops::MulAssign)]
fn mul_assign(self: TestObj, rhs: TestObj) {
self.val *= rhs.val;
}
#[opimps::impl_op_assign(std::ops::MulAssign)]
fn mul_assign(self: TestObj, rhs: &TestObj) {
self.val *= rhs.val;
}
let mut a = TestObj { val: 4 };
let b = TestObj { val: 7 };
a *= b;
assert_eq!(28, a.val);
let mut a = TestObj { val: 4 };
let b = TestObj { val: 7 };
a *= &b;
assert_eq!(28, a.val);
assert_eq!(7, b.val);