- Rust Programming Cookbook
- Claus Matzinger
- 315字
- 2021-06-24 12:27:45
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).
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.
- Cocos2d Cross-Platform Game Development Cookbook(Second Edition)
- INSTANT Mock Testing with PowerMock
- Mastering OpenLayers 3
- 大學(xué)計算機基礎(chǔ)實驗教程
- Getting Started with CreateJS
- C#程序設(shè)計教程
- 數(shù)據(jù)結(jié)構(gòu)與算法JavaScript描述
- Java Web程序設(shè)計
- Microsoft Dynamics GP 2013 Reporting, Second Edition
- 算法訓(xùn)練營:提高篇(全彩版)
- 大模型RAG實戰(zhàn):RAG原理、應(yīng)用與系統(tǒng)構(gòu)建
- QPanda量子計算編程
- Learning Android Application Testing
- Learning D
- Kotlin進階實戰(zhàn)