my_first_lib_rust/
lib.rs

1//! # Art
2//!
3//! A library for modeling artistic concepts.
4
5
6pub use self::kinds::PrimaryColor;
7pub use self::kinds::SecondaryColor;
8pub use self::utils::mix;
9
10pub mod kinds {
11    /// The primary colors according to the RYB color model.
12    #[derive(PartialEq)]
13    pub enum PrimaryColor {
14        Red,
15        Yellow,
16        Blue,
17    }
18
19    /// The secondary colors according to the RYB color model.
20    pub enum SecondaryColor {
21        Orange,
22        Green,
23        Purple,
24    }
25}
26
27pub mod utils {
28    use crate::kinds::*;
29
30    /// Combines two primary colors in equal amounts to create
31    /// a secondary color.
32    pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
33        if c1 == PrimaryColor::Blue && c2 == PrimaryColor::Red {
34            return SecondaryColor::Purple;
35        }
36        SecondaryColor::Green
37    }
38}
39#[cfg(test)]
40mod tests {
41    #[test]
42    fn it_works() {
43        let result = 2 + 2;
44        assert_eq!(result, 4);
45    }
46}