1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Color {
    pub red: u8,
    pub green: u8,
    pub blue: u8,
}

pub fn rgb(red: u8, green: u8, blue: u8) -> Color {
    Color { red, green, blue }
}

macro_rules! derive_color {
    ($doc:expr, $name:ident, $r:expr, $g:expr, $b:expr) => {
        #[doc = $doc]
        pub const $name: Color = Color {
            red: $r,
            green: $g,
            blue: $b,
        };
    };
}

derive_color!("Black.", BLACK, 0, 0, 0);
derive_color!("Red.", RED, 128, 0, 0);
derive_color!("Green.", GREEN, 0, 128, 0);
derive_color!("Yellow.", YELLOW, 128, 128, 0);
derive_color!("Blue.", BLUE, 0, 0, 128);
derive_color!("Magenta.", MAGENTA, 128, 0, 128);
derive_color!("Cyan.", CYAN, 0, 128, 128);
derive_color!("White.", WHITE, 192, 192, 192);
derive_color!("White.", SILVER, 192, 192, 192);
derive_color!("High-intensity light black.", GREY, 128, 128, 128);
derive_color!("High-intensity light black.", BRIGHT_BLACK, 128, 128, 128);
derive_color!("High-intensity light red.", BRIGHT_RED, 255, 0, 0);
derive_color!("High-intensity light green.", BRIGHT_GREEN, 0, 255, 0);
derive_color!("High-intensity light yellow.", BRIGHT_YELLOW, 255, 255, 0);
derive_color!("High-intensity light blue.", BRIGHT_BLUE, 0, 0, 255);
derive_color!("High-intensity light magenta.", BRIGHT_MAGENTA, 255, 0, 255);
derive_color!("High-intensity light cyan.", BRIGHT_CYAN, 0, 255, 255);
derive_color!("High-intensity light white.", BRIGHT_WHITE, 255, 255, 255);