Attribute Macro opimps::impl_op

source ·
#[impl_op]
Expand description

The direct implementation for binary operators. This is used when you only need one implementation.

pub struct TestObj {
    val: i32
}
 
#[opimps::impl_op(std::ops::Mul)]
fn mul(self: TestObj, rhs: TestObj) -> i32 {
   return self.val * rhs.val;
}
 
#[opimps::impl_op(std::ops::Mul)]
fn mul(self: &TestObj, rhs: TestObj) -> i32 {
   return self.val * rhs.val;
}
 
#[opimps::impl_op(std::ops::Mul)]
fn mul(self: &TestObj, rhs: &TestObj) -> i32 {
   return self.val * rhs.val;
}
 
let a = TestObj { val: 4 };
let b = TestObj { val: 7 };
 
assert_eq!(28, &a * &b);
assert_eq!(28, a * b);
 
 
let a = TestObj { val: 4 };
let b = TestObj { val: 7 };
 
assert_eq!(28, &a * b);