siddharth_art/lib.rs
1
2//Now we see to upload our code to crates.io
3
4// first write the documentation comments so other people can understand how to use the code
5// the documentation comments are starts with /// and use markdown for formatting and //! for describing crates and modules
6
7// Documentation comments within items are useful for describing crates and modules especially.
8// Use them to explain the overall purpose of the container to help your users understand the crate’s organization.
9
10// currently commenting this till line 34 we can uncomment and see the output cargo doc --open
11/*
12//! # My Crate
13//!
14//! `my_crate` is a collection of utilities to make performing certain
15//! calculations more convenient.
16
17/// Add one to the number given
18///
19/// # Examples
20///
21/// ```
22/// let arg = 5;
23/// let answer = crate_publish::add_one(arg);
24///
25/// assert_eq!(answer,6);
26/// ```
27
28// we can build the HTML documentation of our crate by using command cargo doc --open
29// pub fn add_one(x:i32)->i32{
30// x+1
31// }
32
33// if we run cargo test than the example written in documentation will run
34*/
35
36// we have a library called art conatins two module kinds and utils
37// An art library with items organized into kinds and utils modules
38
39//! Art
40//!
41//! A library for modeling artistic concepts.
42
43pub use self::kinds::PrimaryColor; // now in doc the enums come at top level
44pub use self::kinds::SecondaryColor;
45pub use self::utils::mix;
46
47
48pub mod kinds{
49 /// The primary colors according to the RYB color model.
50 pub enum PrimaryColor{
51 Red,
52 Blue,
53 Green,
54 }
55 /// The secondary colors according to the RYB color model.
56 pub enum SecondaryColor {
57 Orange,
58 Green,
59 Purple,
60 }
61}
62
63pub mod utils{
64 use crate::kinds::*;
65 /// Combines two primary colors in equal amounts to create
66 /// a secondary color.
67 pub fn mix(c1:PrimaryColor,c2:PrimaryColor) -> SecondaryColor {
68 SecondaryColor::Orange
69 }
70}