2019-01-25 10:42:11 -06:00
|
|
|
#![deny(clippy::wildcard_match_arm)]
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
|
|
enum Color {
|
2019-01-29 12:23:11 -06:00
|
|
|
Red,
|
|
|
|
Green,
|
|
|
|
Blue,
|
|
|
|
Rgb(u8, u8, u8),
|
|
|
|
Cyan,
|
2019-01-25 10:42:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Color {
|
2019-01-29 12:23:11 -06:00
|
|
|
fn is_monochrome(self) -> bool {
|
|
|
|
match self {
|
|
|
|
Color::Red | Color::Green | Color::Blue => true,
|
|
|
|
Color::Rgb(r, g, b) => r | g == 0 || r | b == 0 || g | b == 0,
|
|
|
|
Color::Cyan => false,
|
|
|
|
}
|
|
|
|
}
|
2019-01-25 10:42:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2019-01-29 12:23:11 -06:00
|
|
|
let color = Color::Rgb(0, 0, 127);
|
|
|
|
match color {
|
|
|
|
Color::Red => println!("Red"),
|
|
|
|
_ => eprintln!("Not red"),
|
|
|
|
};
|
|
|
|
match color {
|
|
|
|
Color::Red => {},
|
|
|
|
Color::Green => {},
|
|
|
|
Color::Blue => {},
|
|
|
|
Color::Cyan => {},
|
|
|
|
c if c.is_monochrome() => {},
|
|
|
|
Color::Rgb(_, _, _) => {},
|
|
|
|
};
|
|
|
|
}
|