color_operators/
lib.rs

1#!/usr/bin/env rust
2#![deny(clippy::all, missing_docs, unsafe_code)]
3#![allow(clippy::upper_case_acronyms, clippy::from_over_into, clippy::match_like_matches_macro)]
4
5
6//! A library for converting, comparing, and preforming arithmetic on colors
7//!
8//! # Example
9//!
10//! ```rust
11//! use color_operators::color::Color;
12//! use color_operators::hsl::HSL;
13//! use color_operators::hsv::HSV;
14//! use color_operators::rgb::RGB;
15//!
16//! let c_rgb = Color::new_rgb(255, 42, 90);
17//!
18//! let hsl = HSL::from_json_string(r#"{
19//!     "hue": 346.47887323943667,
20//!     "saturation": 1.0,
21//!     "lightness": 0.5823529411764706
22//! }"#);
23//!
24//! let hsv = HSV::new(346.47887323943667, 0.8352941176470587, 1.0);
25//!
26//! assert_eq!(c_rgb, hsl);
27//! assert_eq!(c_rgb, hsv);
28//! assert_eq!(hsl, hsv);
29//! ```
30
31
32/// Enumerable for currently supported color data structures
33///
34/// # Example
35///
36/// ```rust
37/// use color_operators::color::Color;
38/// use color_operators::rgb::RGB;
39///
40/// let c_rgb = Color::new_rgb(255, 42, 90);
41///
42/// assert!(c_rgb.is_rgb());
43///
44/// let rgb: RGB = c_rgb.into();
45///
46/// assert_eq!(rgb.get("red"), Ok(255));
47/// assert_eq!(rgb.get("green"), Ok(42));
48/// assert_eq!(rgb.get("blue"), Ok(90));
49/// ```
50pub mod color;
51
52
53/// Data structure for Hue, Saturation, Lightness encoded colors
54///
55/// # Example
56///
57/// ```rust
58/// use color_operators::hsl::HSL;
59///
60/// let hsl = HSL::new(120.0, 1.0, 0.5);
61///
62/// assert_eq!(hsl.get("hue"), Ok(120.0));
63/// assert_eq!(hsl.get("saturation"), Ok(1.0));
64/// assert_eq!(hsl.get("lightness"), Ok(0.5));
65/// ```
66pub mod hsl;
67
68
69/// Data structure for Hue, Saturation, Value encoded colors
70///
71/// # Example
72///
73/// ```rust
74/// use color_operators::hsv::HSV;
75///
76/// let hsv = HSV::new(120.0, 1.0, 0.5);
77///
78/// assert_eq!(hsv.get("hue"), Ok(120.0));
79/// assert_eq!(hsv.get("saturation"), Ok(1.0));
80/// assert_eq!(hsv.get("value"), Ok(0.5));
81/// ```
82pub mod hsv;
83
84
85/// Data structure for Red, Green, Blue encoded colors
86///
87/// # Example
88///
89/// ```rust
90/// use color_operators::rgb::RGB;
91///
92/// let rgb = RGB::new(255, 42, 90);
93///
94/// assert_eq!(rgb.get("red"), Ok(255));
95/// assert_eq!(rgb.get("green"), Ok(42));
96/// assert_eq!(rgb.get("blue"), Ok(90));
97/// ```
98pub mod rgb;
99