Add support for custom equality functions in Eq/PartialEq#535
Conversation
769f3fe to
197f615
Compare
adf44d2 to
f9fc07d
Compare
f9fc07d to
d090b1a
Compare
6996bf2 to
e8ac838
Compare
| #[derive(Eq, PartialEq)] | ||
| struct Foo(#[partial_eq(with(eq_special))] NotPartialEq); | ||
| #[derive(Eq, PartialEq)] | ||
| struct Bar(#[eq(with(eq_special))] NotPartialEq); |
There was a problem hiding this comment.
@fredszaq I don't really like the idea of having #[eq(with(...))] attribute. For skip it has sense, since skipping for Eq and PartialEq is essentially the same thing. with(...), however, has only sense for the PartialEq. Of course, derive(Eq) should account for the #[partial_eq(with(...))] presence. But having the #[eq(with(...))] attribute confuses me a lot, implying that Eq trait has a method, which is not the case.
There was a problem hiding this comment.
Fixed. I also added an error if you have #[derive(Hash)] with partial_eq(with) and no hash(skip/with)
|
|
||
| /// Mapping from [`syn::Field`] marked with an [`attr::With`] to the [`syn::Path`] of the alternate | ||
| /// eq function. | ||
| type FieldsWithAlternateEqFunction = HashMap<usize, syn::Path>; |
There was a problem hiding this comment.
@fredszaq let's stick to the same terminology everywhere and just call it "custom function".
There was a problem hiding this comment.
done, changed also on the hash derive that was also using the alternate terminology
Synopsis
This adds the possibility to use custom functions to perform the equality check in
PartialEq/Eqderives. This is quite useful when wrapping types without aPartialEq/EqimplSolution
This builds on #532 and reuse the
FieldAttributesforHash, I moved the struct toutils::attrand renamed itWithOrSkip.I removed fields types that have a
withattribute from the automatically addedwhere Type: Eqbound automatically generated by theEqderive. This seems like the thing to do as if you're using a custom function it most probably means the field doesn't implementEq.While this is not part of the roadmap for PartialEq, defined in #163 this is something that will be quite useful for people migrating form
derivativeas this was something supported by this crateChecklist