Skip to content

Commit

Permalink
doc doc(inline) and doc(no_inline)
Browse files Browse the repository at this point in the history
  • Loading branch information
steveklabnik committed Aug 10, 2017
1 parent 99e943c commit bc9e082
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/doc/rustdoc/src/the-doc-attribute.md
Expand Up @@ -94,7 +94,63 @@ it will not.
These forms of the `#[doc]` attribute are used on individual items, to control how
they are documented.

## `#[doc(no_inline)]`
## `#[doc(no_inline)]`/`#[doc(inline)]`

These attributes are used on `use` statements, and control where the documentation shows
up. For example, consider this Rust code:

```rust
pub use bar::Bar;

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

The documentation will generate a "Reexports" section, and say `pub use bar::Bar;`, where
`Bar` is a link to its page.

If we change the `use` line like this:

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

Instead, `Bar` will appear in a `Structs` section, just like `Bar` was defined at the
top level, rather than `pub use`'d.

Let's change our original example, by making `bar` private:

```rust
pub use bar::Bar;

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

Here, because `bar` is not public, `Bar` wouldn't have its own page, so there's nowhere
to link to. `rustdoc` will inline these definitions, and so we end up in the same case
as the `#[doc(inline)]` above; `Bar` is in a `Structs` section, as if it were defined at
the top level. If we add the `no_inline` form of the attribute:

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

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

Now we'll have a `Reexports` line, and `Bar` will not link to anywhere.

## `#[doc(hidden)]`

Expand Down

0 comments on commit bc9e082

Please sign in to comment.