p_rust 0.1.0

My rust practice
Documentation
//! # Art
//!
//! A library for modeling artistic concepts

pub use self::kinds::PrimaryColor;
pub use self::kinds::SecondaryColor;
pub use self::utils::mix;

pub mod kinds {
    // The primary colors according to the RYB color model.
    pub enum PrimaryColor {
        Red,
        Yellow,
        Blue,
    }

    // The secondary colors according to the RYB color model.
    pub enum SecondaryColor {
        Base(PrimaryColor),
        Orange,
        Green,
        Purple,
    }
}

pub mod utils {
    use crate::ch14_lib2::kinds::{PrimaryColor, SecondaryColor};

    /// Combines two primary colors in equal amounts to create a secondary color.
    ///
    /// # Example
    ///
    /// ```
    /// use p_rust::ch14_lib2::{PrimaryColor, SecondaryColor, mix};
    ///
    /// let mixed_color = mix(PrimaryColor::Red, PrimaryColor::Blue);
    /// assert!(matches!(mixed_color, SecondaryColor::Purple));
    ///
    /// let mixed_color = mix(PrimaryColor::Yellow, PrimaryColor::Yellow);
    /// assert!(matches!(mixed_color, SecondaryColor::Base(PrimaryColor::Yellow)));
    /// ```
    pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
        match (c1, c2) {
            (PrimaryColor::Red, PrimaryColor::Red) => SecondaryColor::Base(PrimaryColor::Red),
            (PrimaryColor::Red, PrimaryColor::Blue) => SecondaryColor::Purple,
            (PrimaryColor::Red, PrimaryColor::Yellow) => SecondaryColor::Orange,
            (PrimaryColor::Yellow, PrimaryColor::Red) => SecondaryColor::Orange,
            (PrimaryColor::Yellow, PrimaryColor::Blue) => SecondaryColor::Green,
            (PrimaryColor::Yellow, PrimaryColor::Yellow) => SecondaryColor::Base(PrimaryColor::Yellow),
            (PrimaryColor::Blue, PrimaryColor::Red) => SecondaryColor::Purple,
            (PrimaryColor::Blue, PrimaryColor::Blue) => SecondaryColor::Base(PrimaryColor::Blue),
            (PrimaryColor::Blue, PrimaryColor::Yellow) => SecondaryColor::Green,
        }
    }
}