Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 918a4ee

Browse files
Add documentation for new example intra-doc link disambiguator
1 parent 5d0a044 commit 918a4ee

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

‎src/doc/rustdoc/src/scraped-examples.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ Rustdoc has a few techniques to ensure these examples don't overwhelm documentat
4747

4848
For a given item, Rustdoc sorts its examples based on the size of the example — smaller ones are shown first.
4949

50+
## Linking to an example source code
51+
52+
You can use intra-doc links to link to a scraped example source file with `example@` disambiguator:
53+
54+
```rust
55+
// If your example is named "foo":
56+
/// [example@foo]
57+
struct Item;
58+
```
59+
60+
By default, the intra-doc link will link to the file containing the `main` function. If you want to
61+
link to another file, you can specify its path:
62+
63+
```rust
64+
// If your example is named "foo":
65+
/// [example@foo/another_file.rs]
66+
struct Item;
67+
```
5068

5169
## FAQ
5270

‎src/doc/rustdoc/src/write-documentation/linking-to-items-by-name.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ rendered as `Foo`. The following prefixes are available: `struct`, `enum`, `trai
9292
`mod`, `module`, `const`, `constant`, `fn`, `function`, `field`, `variant`, `method`, `derive`,
9393
`type`, `value`, `macro`, `prim` or `primitive`.
9494

95+
There is another disambiguator available: `example`. If you want more information about this one,
96+
take a look at the [scraped examples chapter](../scraped-examples.md).
97+
9598
You can also disambiguate for functions by adding `()` after the function name,
9699
or for macros by adding `!` after the macro name. The macro `!` can be followed by `()`, `{}`,
97100
or `[]`. Example:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /