HiveBrain v1.2.0
Get Started
← Back to all entries
snippetrustModerate

How to link to other fns/structs/enums/traits in rustdoc?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howenumsrustdocstructsotherfnslinktraits

Problem

I'm building a Rust library and want to give it some polish. In the rustdoc, I'd sometimes like to link to other parts of the library within the docs, e.g. fns, traits or structs. What is the official syntax for this?

Solution

As of Rust 1.48, Rustdoc now supports direct intra-doc links.

Pre Rust 1.48:

Rustdoc seems to generate mostly deterministic filenames for constituent elements of a crate. Therefore if you have an enum named Complex you can generally link to it using:
Complex


Similarly a struct called Point would look like:
Point


This should carry over to most definitions (fn, trait, and so on).

For referencing elements of a crate at different nesting levels, you can use relative paths (where each module is its own folder):
Point


or use absolute paths:
Point


More of these "conventions", including anchors for specific fields, etc., can be deduced if one builds docs (cargo doc --no-deps --open) and navigates to the field or item they want and takes note of the URL. Remember that only pub items are published to docs.

Context

Stack Overflow Q#31582064, score: 47

Revisions (0)

No revisions yet.