rust_cargo_test/lib.rs
1// ‘///’ 代表文档注释 cargo doc 可以生产文档
2
3
4
5
6//! # Art
7//!
8//! A library for modeling artistic concepts.
9//!
10pub use kinds::PrimaryColor; //使用 pub use 可以将深层次的类型导出 提前到外部 以便其他文件使用
11pub use kinds::SecondaryColor;
12pub use utils::mix;
13
14pub mod kinds {
15 /// The primary colors according to the RYB color model.
16
17 #[derive(Debug)]
18 pub enum PrimaryColor {
19 Red,
20 Yellow,
21 Blue,
22 }
23 /// The secondary colors according to the RYB color model.
24 #[derive(Debug)]
25 pub enum SecondaryColor {
26 Orange,
27 Green,
28 Purple,
29 }
30}
31
32pub mod utils {
33 use crate::kinds::*;
34
35 /// Combines two primary colors in equal amounts to create
36 /// a secondary color.
37 pub fn mix(c1: PrimaryColor, c2: SecondaryColor) -> String {
38 format!("{:?}-{:?}", c1, c2)
39 }
40}
41
42
43/// Adds one to the number given.
44/// # Examples
45/// ```
46/// let five = 5;
47/// assert_eq!(6, cargo::add_one(5));
48/// ```
49
50
51pub fn add_one(x: i32) -> i32 {
52 x+1
53
54}