documentation - 如何编写 crate-wide 文档?

标签 documentation rust

为了确保我的箱子的所有公共(public)工件都被记录(如果是最低限度的开始),我在我的 lib.rs< 中指定了 #![deny(missing_docs)]/。这适得其反。

我希望在顶部写一个文档注释,然后再写代码:

/// Hello world example for Rust.

#![deny(missing_docs)]

fn main() {
    println!("Hello world!");
}

这失败了:

error: an inner attribute is not permitted following an outer doc comment
 --> src/main.rs:3:3
  |
3 | #![deny(missing_docs)]
  |   ^
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.

反转顺序,属性在前,评论在后:

#![deny(missing_docs)]

/// Hello world example for Rust.

fn main() {
    println!("Hello world!");
}

同样失败:

error: missing documentation for crate
 --> src/main.rs:1:1
  |
1 | / #![deny(missing_docs)]
2 | |
3 | | /// Hello world example for Rust.
4 | |
5 | | fn main() {
6 | |     println!("Hello world!");
7 | | }
  | |_^
  |
note: lint level defined here
 --> src/main.rs:1:9
  |
1 | #![deny(missing_docs)]
  |         ^^^^^^^^^^^^

我找不到如何真正为 crate 本身编写文档。我应该如何编写 crate 的文档以满足 #![deny(missing_docs)]

最佳答案

我在 book's Publishing a Crate to Crates.io section 中找到了隐藏的金 block .

常规文档注释(以 /// 开头)记录下一个 项目,但是箱子不是下一个。

解决方案是改用另一种注释,这次以 //! 开头,它记录了封闭项。

突然间它起作用了:

#![deny(missing_docs)]

//! Hello world example for Rust.

fn main() {
    println!("Hello world!");
}

关于documentation - 如何编写 crate-wide 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36184407/

相关文章:

.net - .NET 的 HTML 文档生成器

c# - 如何着手将文档\帮助实现到 WPF 应用程序中?

rust - |x| 的类型是什么移动|y| x+y?

php - reSTLer 资源管理器提示查看器与 REQUEST_BODY json

architecture - 编写可维护的事件驱动代码

c# - 缺少 WCF 服务的 xml 注释的编译器警告

rust - 我可以有一个泛型类型绑定(bind),要求该类型是一个特征吗?

rust - 在 GTK4 中制作可点击框

rust - 我可以禁用 Release模式的开发依赖功能吗?

rust - 是否有访问可变元素容器的通用方法?