Exclude field when deriving PartialEq
I would also recommend the derivative
crate if you need a more sophisticated form of #[derive]
.
If you only need something like this once or twice, it may be easier to just implement the required traits manually rather than derive them. PartialEq
and Eq
are very easy to implement yourself:
impl PartialEq for UndirectedGraph {
fn eq(&self, other: &Self) -> bool {
self.nodes == other.nodes
}
}
impl Eq for UndirectedGraph {}
No, there is no way to do that currently and I doubt it will be supported.
You could consider making the fields that you want to compare into a sub-struct which is derived, which would make the implementation for the larger struct trivial.
Check out the derivative create (docs). It provides alternate derive
macros with more power than the standard library versions, including ways to ignore fields for Hash
and PartialEq
traits.