Skip to content

feat: add doc attributes section to documentation #1323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/meta/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Use `cargo test` to run all tests (including documentation tests), and `cargo te

These commands will appropriately invoke `rustdoc` (and `rustc`) as required.

### Doc comments
## Doc comments

Doc comments are very useful for big projects that require documentation. When
running Rustdoc, these are the comments that get compiled into
Expand Down Expand Up @@ -65,6 +65,43 @@ $ rustc doc.rs --crate-type lib
$ rustdoc --test --extern doc="libdoc.rlib" doc.rs
```

## Doc attributes

Below are a few examples of the most common `#[doc]` attributes used with `rustdoc`.

### `inline`

Used to inline docs, instead of linking out to separate page.

```rust
#[doc(inline)]
pub use bar::Bar;

/// bar docs
mod bar {
/// the docs for Bar
pub struct Bar;
}
```

### `no_inline`
Used to prevent linking out to separate page or anywhere.

```rust
// Example from libcore/prelude
#[doc(no_inline)]
pub use crate::mem::drop;
```

### `hidden`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all covered more deeply in the rustdoc book here. Would a better change be to add an example for the hidden attribute there? Or, is it important to have this covered in RBE?


Using this tells `rustdoc` not to include this in documentation:
```rust,editable
// Example from the futures-rs library
#[doc(hidden)]
pub use self::async_await::*;
```

### See also:

* [The Rust Book: Making Useful Documentation Comments][book]
Expand Down