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
41
42
43
44
45
46
47
48
49
50
51
52
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
impl From<(u8, u8, u8, u8)> for Color {
fn from(tuple: (u8, u8, u8, u8)) -> Color {
Color {
r: tuple.0,
g: tuple.1,
b: tuple.2,
a: tuple.3,
}
}
}
impl From<(u8, u8, u8)> for Color {
fn from(tuple: (u8, u8, u8)) -> Color {
Color {
r: tuple.0,
g: tuple.1,
b: tuple.2,
a: 255,
}
}
}
impl From<[u8; 4]> for Color {
fn from(array: [u8; 4]) -> Color {
Color {
r: array[0],
g: array[1],
b: array[2],
a: array[3],
}
}
}
impl From<[u8; 3]> for Color {
fn from(array: [u8; 3]) -> Color {
Color {
r: array[0],
g: array[1],
b: array[2],
a: 255,
}
}
}