cargoPublishLRC/
lib.rs

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
/* 
* # 文档注释
*     文档注释会生成HTML文档
*     * 三线杠 可以指吃MD注解来个实话文本
* # Examples
* ```
* let arg = 5;
* let answer = _18_1_cargo_pub::add_one(arg);
* assert_eq!(6, answer);
* ~~~
* 文档常用 
* # #通常用来定义标题
* 内容:
*     Examples: 
*     Panics: 函数可能会出现panic!的场景;
*     Errors: 如果这个函数返回Result;此部分描述什么情况会造成这些错误
*     Safety: 如果这个函数使用 unsafe 代码(这会在第十九章讨论),这一部分应该会涉及到期望函数调用者支持的确保 unsafe 块中代码正常工作的不变条件(invariants)
* 
* 文档注释作为测试
*     cargo 回想测试一样运行文档中的实例代码;
*  
* //! 为包含注释的项,而不是位于注释之后的项增加文档。这通常用于 crate 根文件(通常是 src/lib.rs)或模块的根文件为 crate 或模块整体提供文档。
*
**/

//! # My Crate
//!
//! `my_crate` is a collection of utilities to make performing certain
//! calculations more convenient.

/// Adds one to the number given.
///
/// # Examples
///
/// ```
/// let arg = 5;
/// let answer = _18_1_cargo_pub::add_one(arg);
///
/// assert_eq!(6, answer);
/// ```
pub fn add_one(x: i32) -> i32 {
    x + 1
}