As a newcomer to Rust, I\'ve stumbled upon two apparently valid ways of running a match
on a reference type.
I\'ve defined an enum:
enum
As of Rust 1.26, the idiomatic solution is neither; you don't have to dereference the value or add &
to the patterns:
fn contains_blue(&self) -> bool {
match self {
Color::Blue => true,
Color::Teal => true,
Color::Purple => true,
_ => false,
}
}
This is thanks to improved match ergonomics.
You can also use pattern alternation in this case:
match self {
Color::Blue | Color::Teal | Color::Purple => true,
_ => false,
}