colored/
customcolors.rs
1#[derive(Debug, Copy, Clone, PartialEq, Eq)]
3pub struct CustomColor {
4 pub r: u8,
6 pub g: u8,
8 pub b: u8,
10}
11
12impl CustomColor {
14 pub fn new(r: u8, g: u8, b: u8) -> Self {
16 Self { r, g, b }
17 }
18}
19
20impl From<(u8, u8, u8)> for CustomColor {
21 fn from((r, g, b): (u8, u8, u8)) -> Self {
22 Self::new(r, g, b)
23 }
24}
25
26#[cfg(test)]
27mod tests {
28 use crate::*;
29 #[cfg_attr(feature = "no-color", ignore)]
30 #[test]
31 fn main() {
32 let my_color = CustomColor::new(0, 120, 120);
33 insta::assert_snapshot!("Greetings from Ukraine".custom_color(my_color));
34 }
35
36 #[test]
37 fn from_tuple() {
38 let tuple = (1u8, 255u8, 0u8);
39 let cc = CustomColor::from(tuple);
40
41 assert_eq!(cc.r, tuple.0);
42 assert_eq!(cc.g, tuple.1);
43 assert_eq!(cc.b, tuple.2);
44 }
45}