To elaborate some more, the BitOr
operator would need to be implemented for your enum
, and it consumes both the operands to produce something new. Unless you have a logical way of choosing a "winner" based on values (in contrast with combining the operands or choosing based on order), one of these wouldn't work how you like even if you implement the operator:
if let Color::Rgb(225, 0, 0) = c1 | c2 | c3 { ... }
if let Color::Rgb(225, 0, 0) = c3 | c2 | c1 { ... }
Another approach which does work is
if let (Color::Rgb(225, 0, 0), _, _)
| (_, Color::Rgb(225, 0, 0), _)
| (_, _, Color::Rgb(225, 0, 0)) = (c1, c2, c3)
{
Or
#[derive(PartialEq)]
enum Color { ... }
const RED: Color = Color::Rgb(225, 0, 0);
if let (RED, _, _) | (_, RED, _) | (_, _, RED) = (c1, c2, c3) {
In these cases, if any of the |
-separated patterns match, the if let
as a whole will match.
More about patterns.