PartialEq + "compare with" for two fields?
Dushistov opened this issue · 0 comments
Dushistov commented
Describe the bug
I have type like this:
struct Foo {
default_idx: Option<usize>,
list: Vec<Boo>,
//many other fields
}
I want generate PartialEq
in such way that:
fn eq(&self, o: &Foo) -> bool {
self.default_idx.map(|idx| &self.list[idx]) == o.default_idx.map(|idx| &o.list[idx]) &&
// && self.other_fields == o.other_fields
It would be nice if there is way to generate code for comparing two fields at once.
The most simple way as I see will be syntax like this:
#[derivative(PartialEq(fn = compare_foo))]
struct Foo {
#[derivative(PartialEq="ignore")]
default_idx: Option<usize>,
list: Vec<Boo>,
//many other fields
}
and it generate compare_foo
function that compare only many other fields
:
fn compare_foo(lhs: &Foo, rhs: &Foo) -> bool {
self.other_fields == o.other_fields
}
so I can write PartialEq
by hands and compare several special fields in the way I want,
and then use generated compare_foo
for other fields.
- Version of
derivative
: 1.0.3