File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44在 Rust 里面注释分成两种,行注释和块注释。它的形式和 C 语言是一样的。
55两种注释分别是:
66> 1 . 行注释使用 ` // ` 放在注释前面。比如:
7- ` // I love Rust, but I hate Rustc. `
8- 2 . 块注释分别使用` /* ` 和` */ ` 包裹需要注释的内容。比如:
9- ` /* W-Cat 是个大胖猫,N-Cat 是个高度近视猫。*/ `
7+ ```
8+ // I love Rust, but I hate Rustc.
9+ ```
10+
11+ > 2 . 块注释分别使用` /* ` 和` */ ` 包裹需要注释的内容。比如:
12+ ```
13+ /* W-Cat 是个大胖猫,N-Cat 是个高度近视猫。*/
14+ ```
1015
1116## 文档
1217Rust 自带有文档功能的注释,分别是` /// ` 和` //! ` 。支持 Markdown 格式
13181 . ` /// ` 用来描述的它后面接着的项。
14192 . ` //! ` 用来描述包含它的项,一般用在模块文件的头部。
1520比如在 main.rs 文件中输入以下内容:
16- ``` rust
17- // ! # The first line
18- // ! The second line
1921
20- /// Adds one to the number given.
21- ///
22- /// # Examples
23- ///
24- /// ```
25- /// let five = 5;
26- ///
27- /// assert_eq!(6, add_one(5));
28- /// # fn add_one(x: i32) -> i32 {
29- /// # x + 1
30- /// # }
31- /// ```
32- fn add_one (x : i32 ) -> i32 {
33- x + 1
34- }
35- ```
22+ //! # The first line
23+ //! The second line
24+ /// Adds one to the number given.
25+ ///
26+ /// # Examples
27+ ///
28+ /// ```
29+ /// let five = 5;
30+ ///
31+ /// assert_eq!(6, add_one(5));
32+ /// # fn add_one(x: i32) -> i32 {
33+ /// # x + 1
34+ /// # }
35+ /// ```
36+ fn add_one(x: i32) -> i32 {
37+ x + 1
38+ }
39+
40+
3641### 生成 html 文档
3742* ` rustdoc main.rs `
3843
You can’t perform that action at this time.
0 commit comments