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

How it works...

Markdown is a great language that allows for creating formatted documentation quickly. However, feature support is typically tricky, so check out Rust's RFC for supported formatting (https://github.com/rust-lang/rfcs/blob/master/text/0505-api-comment-conventions.md) to find out whether some more advanced statements can be used. In general, writing documentation is dreaded by most developers, which is why it's very important to make it as simple and effortless as possible. The /// pattern is quite common and has been expanded in Rust so that the documentation can apply to the code that follows (///) or that contains it (//!). Examples can be seen in step 1 and step 4.

The approach the Rust project chose allows for a few lines explaining the (public) function, and then the rustdoc compiler (invoked in step 2 with cargo doc) does the rest: exposing public members, cross-linking, listing all of the available types and modules, and much more. While the output is fully customizable (step 6), the default is already visually quite appealing (we think). 

By default, cargo doc builds the documentation for the entire project—including dependencies. 

Special sections (step 3) add another dimension to the documentation output: they allow for IDEs or editors to make some sense of the provided information and highlight, for example, that (and when) a function may panic. The examples section in your newly generated documentation will even compile and run code in the form of doctests (see the Testing your documentation recipe) so you will be notified when your examples become invalid.

The rustdoc output is also independent of a web server, which means that it can be used wherever static hosting is supported. In fact, the Rust project builds and serves every crate's documentation that is hosted on https://crates.io, on https://docs.rs

Now that we can create documentation successfully, we should move on to the next recipe.

主站蜘蛛池模板: 山阴县| 海宁市| 苏州市| 磐安县| 锡林浩特市| 竹溪县| 文登市| 苗栗县| 綦江县| 杭州市| 赤水市| 阿尔山市| 富宁县| 嘉定区| 宝兴县| 长白| 宝兴县| 通渭县| 阜新| 岳阳县| 赤水市| 甘肃省| 顺义区| 牡丹江市| 东阿县| 平顶山市| 罗江县| 隆化县| 栾川县| 岑溪市| 绵竹市| 延津县| 蒙山县| 通许县| 清水河县| 沂源县| 六安市| 化德县| 台中市| 平罗县| 奉新县|