gmaps_static/
color.rs

1use std::fmt;
2
3pub static BLACK: &Color = &Color::Black;
4pub static BROWN: &Color = &Color::Brown;
5pub static GREEN: &Color = &Color::Green;
6pub static PURPLE: &Color = &Color::Purple;
7pub static YELLOW: &Color = &Color::Yellow;
8pub static BLUE: &Color = &Color::Blue;
9pub static GRAY: &Color = &Color::Gray;
10pub static ORANGE: &Color = &Color::Orange;
11pub static RED: &Color = &Color::Red;
12pub static WHITE: &Color = &Color::White;
13
14#[derive(Clone)]
15pub enum Color {
16    Black,
17    Brown,
18    Green,
19    Purple,
20    Yellow,
21    Blue,
22    Gray,
23    Orange,
24    Red,
25    White,
26    Rgb(u8, u8, u8),
27}
28
29impl Color {
30    pub fn new(r: u8, g: u8, b: u8) -> Self {
31        Color::Rgb(r, g, b)
32    }
33}
34
35impl fmt::Display for Color {
36    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37        use Color::*;
38
39        match &self {
40            Black => write!(f, "black"),
41            Brown => write!(f, "brown"),
42            Green => write!(f, "green"),
43            Purple => write!(f, "purple"),
44            Yellow => write!(f, "yellow"),
45            Blue => write!(f, "blue"),
46            Gray => write!(f, "gray"),
47            Orange => write!(f, "orange"),
48            Red => write!(f, "red"),
49            White => write!(f, "white"),
50            Rgb(r, g, b) => write!(f, "0x{:02x}{:02x}{:02x}", r, g, b,),
51        }
52    }
53}
54
55impl From<(u8, u8, u8)> for Color {
56    fn from(rgb: (u8, u8, u8)) -> Self {
57        let (r, g, b) = rgb;
58        Color::new(r, g, b)
59    }
60}
61
62impl From<(i32, i32, i32)> for Color {
63    fn from(rgb: (i32, i32, i32)) -> Self {
64        let (r, g, b) = rgb;
65        Color::new(r as u8, g as u8, b as u8)
66    }
67}