rust - 如何记录来自 Rust 编译器插件的宏?

标签 rust rustdoc rust-compiler-plugin

我注意到编译器插件经常提供文档甚至不会提及的宏。它们以编程方式注册和创建,而不是以 rustdoc 识别的语法定义。自然不能出文档。

我正在寻找一种方法来解决这个问题,一种在编译时为包中不存在的宏生成文档的方法。

我注意到语法 crate 也可以从这样的事情中受益。例如,quote_item 完全没有文档记录。我什至找不到注册它的代码。

最佳答案

一种可能性是做什么the compiler does :创建一个空的 macro_rules! 宏并将文档附加到它。例如。如果一个 crate 定义了接受单个表达式的 foo,那么写一些类似的东西

/// Documentation
#[macro_export]
macro_rules! foo {
     ($e: expr) => ({ /* syntax extension */ })
}

I notice the syntax crate could benefit from such a thing as well. quote_item, for instance, is completely undocumented. I can't even find the code that registers it.

您可以 search the Rust source for quote_item ,这有两个原因:它提供了一些示例,并且还允许您追踪定义。后者使用 Rust's DXR instance 更容易它可以搜索带引号的东西(即可以找到字符串),并包括各种源代码导航技巧(如跳转到定义)。

关于rust - 如何记录来自 Rust 编译器插件的宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34845752/

相关文章:

rust - 在接受特征对象的方法中使用关联函数

rust - 为什么从 TcpStream 更改为特征会导致 "cannot borrow immutable borrowed content as mutable"?

rust - 你如何处理 "could not parse code block as Rust code"rustdoc 警告?

Rust 发现,配置文件未按预期工作

compiler-construction - 如何在编译器插件中修改 crate 的所有项目?

rust - 我可以在稳定的 Rust 上使用编译器插件吗?

rust - 无需代码重复即可在单项测试中多次 panic

error-handling - 合并两种错误类型最惯用的方法是什么?

rust - 如何将任意 Markdown 文件包含为文档属性?

rust - 如何在编译器插件中获取结构体字段和字段类型?