官术网_书友最值得收藏!

Writing documentation

To write documentation, we have special symbols for marking the start of documentation comments (doc comments hereafter). Docs are written in a similar fashion, the way we write comments, but they are treated differently compared to ordinary comments and are parsed by rustdoc. The doc comments are divided into two levels and use separate symbols to mark the start of the doc comment:

  • Item level: These comments are meant for items within the module such as structs, enum declarations, functions, trait constants, and so on. They should appear above the item. For single-line comments, they start with ///, while multi-line comments begin with /** and end with */.
  • Module level: These are comments that appear at the root level, i.e., main.rslib.rs, or any other module, and use //! to mark the start of a line comment  or /*! for multi-line comments  before ending them with */. They are suitable for giving a general overview of your crate and example usage.

Within the doc comment, you can write docs using the usual markdown syntax. It also supports writing valid Rust code within backticks (```let a = 23;```), which becomes part of documentation tests.

The preceding notation for writing comments is actually a syntatic sugar for the #[doc="your doc comment"] attribute. These are called doc attributes. When rustdoc parses the /// or /** lines, it converts them into these doc attributes. Alternatively, you can also write docs using these doc attributes.

主站蜘蛛池模板: 安多县| 江西省| 岑溪市| 镇沅| 兴义市| 镇平县| 太仆寺旗| 新民市| 呼伦贝尔市| 仁化县| 梅州市| 曲麻莱县| 双柏县| 陈巴尔虎旗| 阿坝县| 东丽区| 莱州市| 汉中市| 东丰县| 延津县| 阳原县| 阳信县| 青川县| 青海省| 栖霞市| 兴国县| 大石桥市| 林西县| 巴林右旗| 鹰潭市| 佳木斯市| 通许县| 临澧县| 禹州市| 周口市| 新昌县| 安吉县| 博客| 沧源| 涟源市| 普陀区|