rustmarkdownrust-cargorustdoc

How to link to a specific section in Rust documentation


Suppose I place a header in the documentation for a Rust module, src/module_a/mod.rs:

# Header

Some text.

I know how to link to this header from other parts of src/module_a/mod.rs using standard markdown syntax, and I know how to link to module_a from other modules using standard Cargo doc syntax. But I'm not sure how to link directly to Header within module_a from another module. Does anyone know?


Solution

  • You would use the [text](path) syntax and include a #-suffixed "anchor" for the heading. The path portion can still use Rust's shorthand syntax.

    Here's an example that could be put in module_b:

    //! Here's is a link to the [Header](crate::module_a#header) section.