rgba_simple/
lib.rs

1#![warn(clippy::all, clippy::pedantic)]
2#![allow(clippy::cast_sign_loss)]
3#![allow(clippy::cast_possible_truncation)]
4#![allow(clippy::cast_precision_loss)]
5#![doc = include_str!("../README.md")]
6mod channel;
7pub(crate) use channel::Channel;
8mod colorerror;
9pub use colorerror::ColorError;
10mod hex;
11pub use hex::Hex;
12mod rgb;
13pub use rgb::RGB;
14mod rgba;
15pub use rgba::RGBA;
16#[cfg(feature = "gdk")]
17mod gdk_impl;
18
19/// An enumeration of primary and secondary colors
20pub enum PrimaryColor {
21    Black,
22    White,
23    Red,
24    Green,
25    Blue,
26    Yellow,
27    Magenta,
28    Cyan,
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn from_hex() {
37        let red_hex = String::from("#ff0000");
38        let red: RGB<u8> = PrimaryColor::Red.into();
39        assert_eq!(red, RGB::<u8>::from_hex(&red_hex).unwrap());
40    }
41
42    #[test]
43    fn to_hex() {
44        let blue_hex = String::from("#0000ff");
45        let blue: RGB<u8> = PrimaryColor::Blue.into();
46        assert_eq!(blue.to_hex(), blue_hex);
47    }
48
49    #[test]
50    fn from_hex_float() {
51        let red_hex = String::from("#ff0000");
52        let red: RGBA<f64> = RGBA::from(PrimaryColor::Red);
53        assert_eq!(red, RGBA::<f64>::from_hex(&red_hex).unwrap());
54    }
55
56    #[test]
57    fn to_hex_float() {
58        let blue_hex = String::from("#0000ff");
59        let blue: RGB<f64> = RGB::from(PrimaryColor::Blue);
60        assert_eq!(blue.to_hex(), blue_hex);
61    }
62}