gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 07:59:52 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com