1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
// lib.rs for anpub // lib annotation, test, pub /* create lib project $ cargo new anpub --lib --vcs none use release build profile $ cargo build --releasea use dev build profile $ cargo build Cargo.toml file [profile.dev] opt-levelb = 0 [profile.release] opt-level = 3 show document $ cargo doc --open */ //! # anpub crate //! //! `anpub` is a collection of utilities to make performing certain //! calculations more convenient, and modeling artistic concepts. pub use self::kinds::PrimaryColor; pub use self::kinds::SecondaryColor; pub use self::utils::mix; /// Adds one to the number given. /// /// # Examples /// /// ``` /// let arg = 5; /// let ans = anpub::add_one(arg); /// /// assert_eq!(6, ans); /// ``` pub fn add_one(x: i32) -> i32 { x + 1 } pub mod kinds { /// The primary colors according to the RYB color model. #[derive(Debug)] pub enum PrimaryColor { Red, Yellow, Blue, } /// The secondary colors according to the RYB color model. #[derive(Debug)] pub enum SecondaryColor { Orange, Green, Purple, } } pub mod utils { use crate::kinds::*; /// Combines two primary colors in equal amounts to create /// a secondary color. pub fn mix(_c1: PrimaryColor, _c2: PrimaryColor) -> SecondaryColor { crate::kinds::SecondaryColor::Purple } } #[cfg(test)] mod tests { #[test] fn test_add_one() { use super::*; assert_eq!(3 + 1, add_one(3)); } }