我注意到编译器插件经常提供文档甚至不会提及的宏。它们以编程方式注册和创建,而不是以 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/