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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use super::{Hsl, Rgb};
use crate::{converters::*, ColorAlpha, ColorTuple, ColorTupleA};

impl From<&ColorTuple> for Hsl {
  fn from(t: &ColorTuple) -> Hsl {
    let (h, s, l) = *t;
    Hsl::new(h, s, l, None)
  }
}

impl From<ColorTuple> for Hsl {
  fn from(t: ColorTuple) -> Hsl {
    Hsl::from(&t)
  }
}

impl From<&ColorTupleA> for Hsl {
  fn from(t: &ColorTupleA) -> Hsl {
    let (h, s, l, a) = *t;
    Hsl::new(h, s, l, Some(a))
  }
}

impl From<ColorTupleA> for Hsl {
  fn from(t: ColorTupleA) -> Hsl {
    Hsl::from(&t)
  }
}

fn from_rgb(rgb: &Rgb) -> Hsl {
  let a = rgb.get_alpha();
  let tuple: ColorTuple = rgb.into();
  let mut hsl = Hsl::from(rgb_to_hsl(&tuple));
  hsl.set_alpha(a);
  hsl
}

impl From<&Rgb> for Hsl {
  fn from(rgb: &Rgb) -> Self {
    from_rgb(rgb)
  }
}
impl From<&mut Rgb> for Hsl {
  fn from(rgb: &mut Rgb) -> Self {
    from_rgb(rgb)
  }
}
impl From<Rgb> for Hsl {
  fn from(rgb: Rgb) -> Self {
    from_rgb(&rgb)
  }
}

//
//
//
// INTO
//
impl<'a> Into<ColorTuple> for &'a mut Hsl {
  fn into(self) -> ColorTuple {
    let Hsl { h, s, l, .. } = *self;
    (h, s, l)
  }
}
impl<'a> Into<ColorTuple> for &'a Hsl {
  fn into(self) -> ColorTuple {
    let Hsl { h, s, l, .. } = *self;
    (h, s, l)
  }
}

impl Into<ColorTuple> for Hsl {
  fn into(self) -> ColorTuple {
    self.as_ref().into()
  }
}

impl<'a> Into<ColorTupleA> for &'a Hsl {
  fn into(self) -> ColorTupleA {
    let Hsl { h, s, l, .. } = *self;
    (h, s, l, self.get_alpha())
  }
}
impl<'a> Into<ColorTupleA> for &'a mut Hsl {
  fn into(self) -> ColorTupleA {
    let Hsl { h, s, l, .. } = *self;
    (h, s, l, self.get_alpha())
  }
}

impl Into<ColorTupleA> for Hsl {
  fn into(self) -> ColorTupleA {
    self.as_ref().into()
  }
}