I have the following enum:
enum Token {
Word(String),
Semicolon,
Comma
}
I do not implement Eq
. I want to write a function to match the above through type comparisons:
fn expect(t: &Token, const_t: &Token) -> bool {
match (t, const_t) {
(&Token::Semicolon, &Token::Semicolon) => true,
(&Token::Comma, &Token::Comma) => true,
_ => false,
}
}
The above code is working, but has poor scalablity. If I have 100 variants, I will have a lot of helper functions and will rely on the default match _
a lot.
I don't see an easy way to hide the different variants of the Enum
to simply say "I want to match up the variants of two similar enums".
Are there any other workaround for this purpose?