summaryrefslogtreecommitdiffstats
path: root/examples/08_enum-custom.rs
blob: 48d3691b1339ed58acbc2542f7afc7cfdd42fcb2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
enum Color {
    Red,
    Green,
    Blue,
    Custom(int, int, int),
}

fn print_color (c: Color) {
    match c {
        Red             => println!("#ff0000"),
        Green           => println!("#00ff00"),
        Blue            => println!("#0000ff"),
        Custom(r, g, b) => println!("#{:02x}{:02x}{:02x}", r, g, b),
    }
}

fn main () {
    print_color(Red);
    print_color(Custom(0x12, 0x45, 0xba));
}