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

Doc attributes

We mentioned that the doc comments that we write get converted into doc attributes form. Apart from those, there are other doc attributes for documentation that can tweak the generated documentation page, and these are applied either at the crate level or at the item level. They are written like #[doc(key = value)]. Some of the most useful doc attributes are as follows:

Crate-level attributes:

  • #![doc(html_logo_url = "image url"): Allows you to add a logo to the top-left of your documentation page.
  • #![doc(html_root_url = "https://docs.rs/slotmap/0.2.1")]: Allows you to set the URL for the documentation page.

  • #![doc(html_playground_url = "https://play.rust-lang.org/")]: Allows you to put a run button near the code example in your documentation so that you can run it directly in the online Rust playground.

Item-level attributes:

  • #[doc(hidden)]: Say you have written the documentation for a public function, foo, as a note to yourself. However, you don't want your consumers to view the documentation. You can use this attribute to tell rustdoc to ignore generating docs for foo.
  • #[doc(include)]: This can be used to include documentation from other files. This helps you separate your documentation from code if it's really long.

For more attributes like these ones, head over to https://doc.rust-lang.org/beta/rustdoc/the-doc-attribute.html.

主站蜘蛛池模板: 桐城市| 沁阳市| 金秀| 定结县| 阳江市| 蚌埠市| 临沧市| 和政县| 吉首市| 永登县| 仙居县| 吕梁市| 太白县| 玉环县| 安新县| 新源县| 公安县| 玉屏| 商丘市| 榆社县| 台南市| 宁国市| 简阳市| 北碚区| 榆林市| 屏南县| 石泉县| 临漳县| 定远县| 芦山县| 桂林市| 安西县| 东城区| 会昌县| 石阡县| 青海省| 会宁县| 鄂托克旗| 类乌齐县| 昌都县| 东辽县|