rust 语法和语义 05 注释
2018-02-28 23:04
281 查看
rust 语法和语义 05 注释
注释:commentsrust的注释主要分为两类:
行注释 line comments和
文档注释 doc comments。
行注释 line comments
同c一样,使用
//开头。
// Line comments are anything after ‘//’ and extend to the end of the line. let x = 5; // This is also a line comment // If you have a long explanation for something, // you can put line comments next to each other. // Put a space between the // and your comment so that it’s // more readable.
整段注释
同c一样,使用
/* */表示。
/* this is block comments, you can put line comments next to each other. */
文档注释 doc comments
使用///表示文档注释 。并内建
Markdown标记支持。
/// Adds one to the number given. /// /// # Examples /// /// ``` /// let five = 5; /// /// assert_eq!(6, add_one(5)); /// # fn add_one(x: i32) -> i32 { /// # x + 1 /// # } /// ``` fn add_one(x: i32) -> i32 { x + 1 }
包含项注释
使用//!注释那些包含这个注释的
crate,mod,或者function。而不是位于注释以后的内容。
经常用于
crate的根文件 lib.rs或者
模块的根文件 mod.rs。
//! # The Rust Standard Library //! //! The Rust Standard Library provides the essential runtime //! functionality for building portable Rust software
文档注释生成
可以使用rustdoc工具来将文档注释生成为 HTML 文档,也可以将代码示例作为测试运行!
参考
The Rust Programming LanguageRust 程序设计语言(第一版) 简体中文版
相关文章推荐
- rust 语法和语义 04 原生类型
- rust 语法和语义 01 变量绑定
- rust 语法和语义 06 分支
- rust 语法和语义 07 循环
- rust 语法和语义 03 表达式 VS 语句
- rust 语法和语义 02 函数
- Rust语法之注释
- [Perl语法篇] 05 -- 变量作用域:our、local、my、state
- Rust的注释
- 复习:JSP基本语法(JSP注释 + JSP指令 + JSP脚本元素 + JSP动作元素)
- discuz门户首页-header文件模板语法详解和注释
- 编写一个程序,查找C语言中的基本语法错误,如圆括号、方括号、花括号不配对等,正确处理引号与注释
- H.264句法和语法总结(四)图像参数集语义
- PHP语法与注释
- 编译原理之词法分析、语法分析、语义分析
- lua语法-程序块(chunk)与注释
- 05-ognl基本语法
- Rust语法之原生数据类型(一)
- 黑马程序员——java基础语法(一)---关键字、标识符、注释、常量、变量、运算符
- Python笔记第1章,流程控制,用户交互,语法要求,变量,字符,注释,模块导入的使用