-implementation out, with a regular comment in its place. That's the first thing
-to notice about this annotation: it uses `///`, instead of `//`. The triple slash
+implementation out, with a regular comment in its place.
+
+The first thing to notice about this annotation is that it uses
+`///` instead of `//`. The triple slash
Rust keeps track of these comments, and uses them when generating
documentation. This is important when documenting things like enums:
Rust keeps track of these comments, and uses them when generating
documentation. This is important when documenting things like enums:
The first line of a documentation comment should be a short summary of its
functionality. One sentence. Just the basics. High level.
The first line of a documentation comment should be a short summary of its
functionality. One sentence. Just the basics. High level.
///
/// Other details about constructing `Rc<T>`s, maybe describing complicated
/// semantics, maybe additional options, all kinds of stuff.
///
/// Other details about constructing `Rc<T>`s, maybe describing complicated
/// semantics, maybe additional options, all kinds of stuff.
are three kinds of headers that are commonly used. They aren't special syntax,
just convention, for now.
are three kinds of headers that are commonly used. They aren't special syntax,
just convention, for now.
least. If your function has a non-trivial contract like this, that is
detected/enforced by panics, documenting it is very important.
least. If your function has a non-trivial contract like this, that is
detected/enforced by panics, documenting it is very important.
slightly less important than `Panics`, because failure is encoded into the type
system, but it's still a good thing to do.
slightly less important than `Panics`, because failure is encoded into the type
system, but it's still a good thing to do.
If your function is `unsafe`, you should explain which invariants the caller is
responsible for upholding.
If your function is `unsafe`, you should explain which invariants the caller is
responsible for upholding.
longer examples in detail, while still preserving the testability of your
documentation. For example, this code:
longer examples in detail, while still preserving the testability of your
documentation. For example, this code:
`cargo test` will not test binary crates, only library ones. This is
due to the way `rustdoc` works: it links against the library to be tested,
but with a binary, there’s nothing to link to.
`cargo test` will not test binary crates, only library ones. This is
due to the way `rustdoc` works: it links against the library to be tested,
but with a binary, there’s nothing to link to.
There are a few more annotations that are useful to help `rustdoc` do the right
thing when testing your code:
There are a few more annotations that are useful to help `rustdoc` do the right
thing when testing your code:
with `text` if it's not code, or using `#`s to get a working example that
only shows the part you care about.
with `text` if it's not code, or using `#`s to get a working example that
only shows the part you care about.
`should_panic` tells `rustdoc` that the code should compile correctly, but
not actually pass as a test.
`should_panic` tells `rustdoc` that the code should compile correctly, but
not actually pass as a test.
Rust has another kind of doc comment, `//!`. This comment doesn't document the next item, but the enclosing item. In other words:
Rust has another kind of doc comment, `//!`. This comment doesn't document the next item, but the enclosing item. In other words:
This is where you'll see `//!` used most often: for module documentation. If
you have a module in `foo.rs`, you'll often open its code and see this:
This is where you'll see `//!` used most often: for module documentation. If
you have a module in `foo.rs`, you'll often open its code and see this:
//! A module for using `foo`s.
//!
//! The `foo` module contains a lot of useful functionality blah blah blah
//! A module for using `foo`s.
//!
//! The `foo` module contains a lot of useful functionality blah blah blah
When you write documentation in Markdown files, you don't need to prefix
the documentation with comments. For example:
When you write documentation in Markdown files, you don't need to prefix
the documentation with comments. For example:
You can control a few aspects of the HTML that `rustdoc` generates through the
`#![doc]` version of the attribute:
You can control a few aspects of the HTML that `rustdoc` generates through the
`#![doc]` version of the attribute:
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
```
This sets a few different options, with a logo, favicon, and a root URL.
```
This sets a few different options, with a logo, favicon, and a root URL.