Linking To Items By Name
Description
rustdoc has syntax to specifiy that you’re trying to link to a type, and it will generate URLs for you. No more relative linking with all the issues it brings.
Syntax
Pre 1.48
pub mod foo {
/// Some docs for Foo
///
/// You may want to use Foo with [Bar].
///
/// [Bar]: ../bar/struct.Bar.html
pub struct Foo;
}
pub mod bar {
/// Some docs for Bar
///
/// You may want to use Bar with [Foo].
///
/// [Foo]: ../foo/struct.Foo.html
pub struct Bar;
}
1.48
pub mod foo {
/// Some docs for Foo
///
/// You may want to use Foo with Bar.
pub struct Foo;
}
pub mod bar {
/// Some docs for Bar
///
/// You may want to use Bar with [crate::foo::Foo].
pub struct Bar;
}
External documentation
- Linking to items by name[fn:linking]
- Feature history[fn:history]
Footnotes
[fn:history]https://blog.rust-lang.org/inside-rust/2020/09/17/stabilizing-intra-doc-links.html
[fn:linking]https://doc.rust-lang.org/stable/rustdoc/linking-to-items-by-name.html