我正在建一个 rust 迹斑斑的图书馆,想把它润色一下.在rustdoc中,我有时想将link转到文档中库的其他部分,例如fn
s、trait
s或struct
s.这个的官方语法是什么?
我正在建一个 rust 迹斑斑的图书馆,想把它润色一下.在rustdoc中,我有时想将link转到文档中库的其他部分,例如fn
s、trait
s或struct
s.这个的官方语法是什么?
As of Rust 1.48, Rustdoc now supports direct intra-doc links.
Pre Rust 1.48:
Rustdoc
似乎为 crate 的组成元素生成了大部分确定性文件名.因此,如果您有一个名为Complex
的enum
,通常可以使用以下链接:
[Complex](enum.Complex.html)
类似地,一个名为Point
的struct
看起来像:
[Point](struct.Point.html)
这应该适用于大多数定义(fn
、trait
等).
要在不同嵌套级别引用 crate 的元素,可以使用相对路径(其中每个模块都是自己的文件夹):
[Point](../model/struct.Point.html)
或者使用绝对路径:
[Point](/crate_name/model/struct.Point.html)
如果一个人构建文档(cargo doc --no-deps --open
)并导航到他们想要的字段或项目,并注意URL,则可以推断出更多这些"约定",包括特定字段的锚定等.请记住,只有发布项目才会发布到文档中.