Compare equality of enums with named fields

Given an enum where some variant(s) have named fields (struct variants, anonymous structs),

enum S {
    Unnamed(i32),
    Named { a: i32 },
}

how can we match pairs of them to write a reasonable equality function (without nested matches, and when we can't rely on a #[derive(PartialEq, Eq)])?

It's easy enough for unnamed variants as here on playground, but I nor rustc see how a match like this:

match (self, other) {
            (S::Named { a }, S::Named { a }) => true,

would be right, nor how to apply @ Bindings.

1 Like
(S::Named { a: a1 }, S::Named { a: a2 }) => ...
4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.