命令行参数
以下是您可以传递给 rustdoc
的参数列表
-h
/--help
:帮助
使用此标志看起来像这样
$ rustdoc -h
$ rustdoc --help
这将显示 rustdoc
的内置帮助,其中主要包含可能的命令行标志列表。
rustdoc
的某些标志是不稳定的;此页面仅显示稳定的选项,--help
将显示所有选项。
-V
/--version
:版本信息
使用此标志看起来像这样
$ rustdoc -V
$ rustdoc --version
这将显示 rustdoc
的版本,它看起来像这样
rustdoc 1.17.0 (56124baa9 2017-04-24)
-v
/--verbose
:更详细的输出
使用此标志看起来像这样
$ rustdoc -v src/lib.rs
$ rustdoc --verbose src/lib.rs
这将启用“详细模式”,这意味着更多信息将被写入标准输出。写入的内容取决于您传递的其他标志。例如,使用 --version
$ rustdoc --verbose --version
rustdoc 1.17.0 (56124baa9 2017-04-24)
binary: rustdoc
commit-hash: hash
commit-date: date
host: host-tuple
release: 1.17.0
LLVM version: 3.9
-o
/--out-dir
:输出目录路径
使用此标志看起来像这样
$ rustdoc src/lib.rs -o target/doc
$ rustdoc src/lib.rs --out-dir target/doc
默认情况下,rustdoc
的输出出现在当前工作目录中名为 doc
的目录中。使用此标志,它会将所有输出放入您指定的目录中。
--crate-name
:控制 crate 的名称
使用此标志看起来像这样
$ rustdoc src/lib.rs --crate-name mycrate
默认情况下,rustdoc
假定您的 crate 的名称与 .rs
文件的名称相同。 --crate-name
允许您使用您选择的任何名称来覆盖此假设。
--document-private-items
:显示非公开的项
使用此标志看起来像这样
$ rustdoc src/lib.rs --document-private-items
默认情况下,rustdoc
只记录可以公开访问的项。
#![allow(unused)] fn main() { pub fn public() {} // this item is public and will be documented mod private { // this item is private and will not be documented pub fn unreachable() {} // this item is public, but unreachable, so it will not be documented } }
--document-private-items
记录所有项,即使它们不是公开的。
-L
/--library-path
:查找依赖项的位置
使用此标志看起来像这样
$ rustdoc src/lib.rs -L target/debug/deps
$ rustdoc src/lib.rs --library-path target/debug/deps
如果您的 crate 有依赖项,rustdoc
需要知道在哪里找到它们。传递 --library-path
会为 rustdoc
提供一个查找这些依赖项的位置列表。
此标志接受任意数量的目录作为其参数,并在搜索时使用所有目录。
--cfg
:传递配置标志
使用此标志看起来像这样
$ rustdoc src/lib.rs --cfg feature="foo"
此标志接受与 rustc --cfg
相同的值,并使用它来配置编译。上面的示例使用了 feature
,但任何 cfg
值都是可接受的。
--check-cfg
:检查配置标志
此标志接受与 rustc --check-cfg
相同的值,并使用它来检查配置标志。
使用此标志看起来像这样
$ rustdoc src/lib.rs --check-cfg='cfg(my_cfg, values("foo", "bar"))'
上面的示例检查每个已知名称和值(target_os
、doc
、test
等),并检查 my_cfg
的值:foo
和 bar
。
--extern
:指定依赖项的位置
使用此标志看起来像这样
$ rustdoc src/lib.rs --extern lazy-static=/path/to/lazy-static
类似于 --library-path
,--extern
是关于指定依赖项的位置的。 --library-path
提供要搜索的目录,而 --extern
则允许您精确指定哪个依赖项位于哪里。
-C
/--codegen
:将 codegen 选项传递给 rustc
使用此标志看起来像这样
$ rustdoc src/lib.rs -C target_feature=+avx
$ rustdoc src/lib.rs --codegen target_feature=+avx
$ rustdoc --test src/lib.rs -C target_feature=+avx
$ rustdoc --test src/lib.rs --codegen target_feature=+avx
$ rustdoc --test README.md -C target_feature=+avx
$ rustdoc --test README.md --codegen target_feature=+avx
当 rustdoc 生成文档,查找文档测试或执行文档测试时,它需要编译一些 rust 代码,至少部分编译。此标志允许您告诉 rustdoc 在运行这些编译时向 rustc 提供一些额外的 codegen 选项。大多数情况下,这些选项不会影响常规文档运行,但如果某些内容依赖于启用的目标功能,或者文档测试需要使用一些其他选项,则此标志允许您影响它。
此标志的参数与 rustc 上的 -C
标志的参数相同。运行 rustc -C help
以获取完整列表。
--test
:将代码示例作为测试运行
使用此标志看起来像这样
$ rustdoc src/lib.rs --test
此标志将运行您的代码示例作为测试。有关更多信息,请参阅关于文档测试的章节。
另请参阅 --test-args
和 --test-run-directory
。
--test-args
:将选项传递给测试运行器
使用此标志看起来像这样
$ rustdoc src/lib.rs --test --test-args ignored
此标志将在运行文档测试时将选项传递给测试运行器。有关更多信息,请参阅关于文档测试的章节。
另请参阅 --test
。
--test-run-directory
:在特定目录中运行代码示例
使用此标志看起来像这样
$ rustdoc src/lib.rs --test --test-run-directory=/path/to/working/directory
此标志将在指定的工作目录中运行您的代码示例。有关更多信息,请参阅关于文档测试的章节。
另请参阅 --test
。
--target
:为指定的目标三元组生成文档
使用此标志看起来像这样
$ rustdoc src/lib.rs --target x86_64-pc-windows-gnu
类似于 rustc
的 --target
标志,这将为与主机三元组不同的目标三元组生成文档。
所有跨编译代码的常见注意事项均适用。
--default-theme
:设置默认主题
使用此标志看起来像这样
$ rustdoc src/lib.rs --default-theme=ayu
设置默认主题(对于浏览器尚未记住页面主题选择器的先前主题选择的用户)。
提供的值应该是主题名称的小写版本。可以在生成的输出中的主题选择器中看到可用的主题集。
请注意,可用的主题集及其外观不一定在 rustdoc 的各个版本之间保持稳定。如果请求的主题不存在,则使用内置的默认主题(当前为 light
)。
--markdown-css
:在渲染 Markdown 时包含更多 CSS 文件
使用此标志看起来像这样
$ rustdoc README.md --markdown-css foo.css
在渲染 Markdown 文件时,这将在生成的 HTML 的 <head>
部分中创建一个 <link>
元素。例如,使用上面的调用
<link rel="stylesheet" type="text/css" href="foo.css">
将被添加。
在渲染 Rust 文件时,将忽略此标志。
--html-in-header
:在 <head>
中包含更多 HTML
使用此标志看起来像这样
$ rustdoc src/lib.rs --html-in-header header.html
$ rustdoc README.md --html-in-header header.html
此标志接受文件列表,并将它们插入到渲染的文档的 <head>
部分中。
--html-before-content
:在内容之前包含更多 HTML
使用此标志看起来像这样
$ rustdoc src/lib.rs --html-before-content extra.html
$ rustdoc README.md --html-before-content extra.html
此标志接受文件列表,并将它们插入到 <body>
标记内,但在 rustdoc
通常在渲染的文档中生成的其他内容之前。
--html-after-content
:在内容之后包含更多 HTML
使用此标志看起来像这样
$ rustdoc src/lib.rs --html-after-content extra.html
$ rustdoc README.md --html-after-content extra.html
此标志接受文件列表,并将它们插入到 </body>
标记之前,但在 rustdoc
通常在渲染的文档中生成的其他内容之后。
--markdown-playground-url
:控制 playground 的位置
使用此标志看起来像这样
$ rustdoc README.md --markdown-playground-url https://play.rust-lang.org/
在渲染 Markdown 文件时,此标志给出 Rust Playground 的基本 URL,用于生成 Run
按钮。
--markdown-no-toc
:不生成目录
使用此标志看起来像这样
$ rustdoc README.md --markdown-no-toc
默认情况下,从 Markdown 文件生成文档时,rustdoc
将生成目录。此标志会阻止这种情况,并且不会生成目录。
-e
/--extend-css
:扩展 rustdoc 的 CSS
使用此标志看起来像这样
$ rustdoc src/lib.rs -e extra.css
$ rustdoc src/lib.rs --extend-css extra.css
使用此标志,您传递的文件的内容将包含在 theme.css
文件的底部。
--sysroot
:覆盖系统根目录
使用此标志看起来像这样
$ rustdoc src/lib.rs --sysroot /path/to/sysroot
类似于 rustc --sysroot
,这允许您更改 rustdoc
在编译代码时使用的系统根目录。
--edition
:控制文档和 doctest 的版本
使用此标志看起来像这样
$ rustdoc src/lib.rs --edition 2018
$ rustdoc --test src/lib.rs --edition 2018
此标志允许 rustdoc
将您的 rust 代码视为给定的版本。它还将使用给定的版本编译 doctest。与 rustc
一样,rustdoc
将使用的默认版本是 2015
(第一个版本)。
--theme
:向文档输出添加主题
使用此标志看起来像这样
$ rustdoc src/lib.rs --theme /path/to/your/custom-theme.css
rustdoc
的默认输出包括两个主题:light
(默认)和 dark
。此标志允许您向输出添加自定义主题。将 CSS 文件传递给此标志会将其作为其他主题选择添加到您的文档中。主题的名称由其文件名确定;名为 custom-theme.css
的主题文件将向文档添加名为 custom-theme
的主题。
--check-theme
:根据默认主题验证自定义主题
使用此标志看起来像这样
$ rustdoc --check-theme /path/to/your/custom-theme.css
虽然 rustdoc
的 HTML 输出在各个版本之间或多或少保持一致,但不能保证主题文件会产生相同的效果。 --theme
标志仍然允许您将主题添加到您的文档中,但为了确保您的主题按预期工作,您可以使用此标志来验证它是否实现了与官方 light
主题相同的 CSS 规则。
--check-theme
是 rustdoc
中的单独模式。当 rustdoc
看到 --check-theme
标志时,它会丢弃所有其他标志,并且仅执行 CSS 规则比较操作。
--crate-version
:控制 crate 版本
使用此标志看起来像这样
$ rustdoc src/lib.rs --crate-version 1.3.37
当 rustdoc
收到此标志时,它将在 crate 根目录的文档的侧边栏中打印额外的“版本(版本)”。您可以使用此标志来区分库的不同版本的文档。
-
:从标准输入加载源代码
如果在命令行上将 -
指定为 INPUT,则 rustdoc
将从 stdin(标准输入流)读取源代码,直到 EOF,而不是从文件系统中读取具有其他指定路径的源代码。
@path
:从路径加载命令行标志
如果在命令行上指定 @path
,则它将打开 path
并从中读取命令行选项。这些选项每行一个;空行表示空选项。该文件可以使用 Unix 或 Windows 样式行尾,并且必须编码为 UTF-8。
--passes
:添加更多 rustdoc passes
此标志已弃用。有关 passes 的更多详细信息,请参阅关于它们的章节。
--no-defaults
:不运行默认 passes
此标志已弃用。有关 passes 的更多详细信息,请参阅关于它们的章节。
-r
/--input-format
:输入格式
此标志已弃用并且不起作用。
Rustdoc 仅支持 Rust 源代码和 Markdown 输入格式。如果文件以 .md
或 .markdown
结尾,则 rustdoc
将其视为 Markdown 文件。否则,它假定输入文件是 Rust。