在我的另一个问题中,我问如何仅公开公开Foo<u32>私有泛型类型 () 的具体变体 ( Foo<T>)。建议的解决方案如下:
mod internal {
/// Private documentation of `Foo`.
pub struct Foo<X> {
/// Private documentation of `x`.
pub x: X,
}
impl Foo<u32> {
pub fn foo() -> u32 {
32
}
}
impl Foo<u8> {
pub fn foo() -> u8 {
8
}
}
}
/// Public documentation of `FooBar`.
pub type FooBar = internal::Foo<u32>;
Run Code Online (Sandbox Code Playgroud)
这是有效的,因为公共 API 只包含FooBar,但不包含Foo。然而,从文档的角度来看,它是缺乏的。cargo doc这是for的输出FooBar:
如你看到的,
我想查看我的程序依赖的库的rust文档.我怎么能把它们拉下来?我找到了标准库的答案的问题,但我正在寻找crates.io依赖项.
我正在尝试为Rust写的一个项目编写文档.其中一个文档需要使用regex::Regex.这是我要写的文档:
/// Return a list of the offsets of the tokens in `s`, as a sequence of `(start, end)`
/// tuples, by splitting the string at each successive match of `regex`.
///
/// # Examples
///
/// ```
/// use rusty_nltk::tokenize::util::regexp_span_tokenize;
/// use regex::Regex;
///
/// let s = "Good muffins cost $3.88\nin New York. Please buy me
/// two of them.\n\nThanks.";
/// let regex = regex::Regex::new(r"\s").unwrap();
/// let spans = regexp_span_tokenize(s, regex).unwrap();
/// ```
Run Code Online (Sandbox Code Playgroud)
它给了我这个错误:
---- tokenize::util::regexp_span_tokenize_0 …Run Code Online (Sandbox Code Playgroud) 我有一个项目:
main.rs
module_1/mod.rs
module_2/mod.rs
module_2/module_3/mod.rs
Run Code Online (Sandbox Code Playgroud)
当我运行时cargo doc,我只有文档main.rs,而不是模块.
在我的main.rs身上:
mod module_1;
mod module_2;
fn main() {
...
}
Run Code Online (Sandbox Code Playgroud)
我曾尝试使用///或记录模块 //!.
我找不到rustdoc帮助怎么做.
有人可以解释一下吗?
我遇到过一个案例,我有一个泛型需要满足两个特征。
pub struct FileReader<R: Read + Seek> { /* private fields */ }
Run Code Online (Sandbox Code Playgroud)
这些是标准特征,我可以单独找到它们的实现者。然后我可以看到哪些实现者是常见的并使用其中之一。
然而,这让我考虑是否有一种方法可以查询 - 货物文档、编译器或其他东西来找到实现给定一组特征的可能结构。当泛型具有许多特征条件和/或特征具有许多实现者时,这可能很有用。
Cargo 文档已经有一个用于查询的搜索栏,但它用于使用名称或函数类型进行搜索。没有一个像这样的升级查询。
当您使用Cargo和rustdoc为Rust包生成文档时,我在生成的页面中看不到任何指示它的版本.例如,看一下log crate的文档.有没有办法知道一套文档的版本是哪个版本?
是否可以对 API 的各个部分进行分组?例如相关的函数、类型或常量。
例如,Doxygen 支持这样的分组:
/** \name Some API Grouping
* \{ */
// code //
/* \} */
Run Code Online (Sandbox Code Playgroud)
rustdoc 可以做类似的事情吗?
如果readme Cargo.toml设置了键,doc.rs 会在 crate 的索引页面上呈现 README。在cargo doc本地运行时有没有办法模拟这一点?
如果我添加:
#![doc = r###"contents
of
README.md
here
"###]
Run Code Online (Sandbox Code Playgroud)
作为字面意思,我得到了我正在寻找的行为,但是内联整个 README.md 的副本对于进行更新非常不方便。
我试过:
#![doc = include!("README.md")]
Run Code Online (Sandbox Code Playgroud)
但这给出了一个错误:
error: unexpected token: `include`
--> src/lib.rs:3:10
|
3 | #![doc = include!("README.md")]
| ^^^^^^^
Run Code Online (Sandbox Code Playgroud) 当我运行时cargo doc,它似乎没有为我的项目中的库生成文档。我正在使用最新版本的 Rust,正如这篇文章所回答的:How can I include private module while generated Documentation via Cargo?
这是我的结构:
- services/
- mod.rs
- my_service.rs
- lib.rs
- main.rs
Run Code Online (Sandbox Code Playgroud)
main.rs仅包含要启动的“main”函数:
use test_doc::Core;
fn main() {
Core::start();
}
Run Code Online (Sandbox Code Playgroud)
lib.rs包含实际逻辑:
mod services;
/// Core process
pub struct Core;
impl Core {
pub fn start() -> ! {
loop {
// do stuff here
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后my_service.rs包含更多逻辑:
/// My service should do stuff
pub struct MyService;
impl MyService {
/// …Run Code Online (Sandbox Code Playgroud) 我最近在 crates.io 上发布了我的第一个 crate,我想知道是否可以以更简单的方式维护其文档。
很多板条箱的文档都托管在 GitHub 页面上,所以我想我应该尝试一下。我创建了一个 user.github.io 存储库,生成文档cargo doc并将其推送到其中。一切工作正常,可以从 crates.io 查看文档。
但更新不方便;如果我修改板条箱的文档,我需要:
cargo doc我很确定我做得不对 - 尤其是第 3 点。我可以做些什么来简化这个过程?还有更好的办法吗?