blinksy/color/
convert.rs

1/// Trait for converting from another color type
2pub trait FromColor<Color>: Sized {
3    /// Converts from the source color type
4    fn from_color(color: Color) -> Self;
5}
6
7/// Trait for converting to another color type
8pub trait IntoColor<Color>: Sized {
9    /// Converts into the target color type
10    fn into_color(self) -> Color;
11}
12
13impl<T, U> IntoColor<U> for T
14where
15    U: FromColor<T>,
16{
17    #[inline]
18    fn into_color(self) -> U {
19        U::from_color(self)
20    }
21}
22
23impl<T> FromColor<T> for T {
24    #[inline]
25    fn from_color(color: T) -> T {
26        color
27    }
28}