Skip to main content

hyeonbungi_rust_playground/
lib.rs

1//! # Hyeonbungi Rust Playground
2//!
3//! `hyeonbungi_rust_playground` is a collection of utilities to make performing certain calculations more convenient.
4
5/// Adds one to the number given.
6///
7/// # Examples
8///
9/// ```
10/// let arg = 5;
11/// let answer = hyeonbungi_rust_playground::add_one(arg);
12///
13/// assert_eq!(6, answer);
14/// ```
15pub fn add_one(x: i32) -> i32 {
16    x + 1
17}
18
19pub use self::kinds::PrimaryColor;
20pub use self::kinds::SecondaryColor;
21pub use self::utils::mix;
22
23pub mod kinds {
24    /// The primary colors according to the RYB color model.
25    #[derive(PartialEq)]
26    pub enum PrimaryColor {
27        Red,
28        Yellow,
29        Blue,
30    }
31
32    /// The secondary colors according to the RYB color model.
33    pub enum SecondaryColor {
34        Orange,
35        Green,
36        Purple,
37    }
38}
39
40pub mod utils {
41    use crate::kinds::*;
42
43    /// Combines two primary colors in equal amounts to create a secondary color.
44    pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
45        if (c1 == PrimaryColor::Red && c2 == PrimaryColor::Yellow)
46            || (c1 == PrimaryColor::Yellow && c2 == PrimaryColor::Red)
47        {
48            SecondaryColor::Orange
49        } else if (c1 == PrimaryColor::Red && c2 == PrimaryColor::Blue)
50            || (c1 == PrimaryColor::Blue && c2 == PrimaryColor::Red)
51        {
52            SecondaryColor::Purple
53        } else {
54            SecondaryColor::Green
55        }
56    }
57}