-
Notifications
You must be signed in to change notification settings - Fork 143
Open
Labels
Description
Currently we have derives for Add,Sub, etc...
What would it take to implement derives for traits with &rhs? E.g.,
#[derive(Add, AddRef)]
pub struct MyType{
a: usize,
b: u128,
}
// Expansion of Add macro
// =================================
#[automatically_derived]
impl derive_more::Add for MyType {
type Output = MyType;
#[inline]
#[track_caller]
fn add(self, rhs: MyType) -> MyType {
MyType {
a: self.a.add(rhs.a),
b: self.b.add(rhs.b),
}
}
}
// Potential expansion of AddRef macro
// =================================
#[automatically_derived]
impl derive_more::Add<&MyType> for MyType {
type Output = MyType;
#[inline]
#[track_caller]
fn add(self, rhs: &MyType) -> MyType {
MyType {
a: self.a.add(&rhs.a),
b: self.b.add(&rhs.b),
}
}
}