如果在模块中定义了宏,如何正确编写宏文档? [英] How do I properly write macro documentation if the macro is defined in a module?
问题描述
现在,我试图用一个例子来记录宏。 显然,我需要手动指定要求宏的条形码行:
///```
///##[macro_use] extern crate foo;
/// //一些代码
///```
但是,我现在得到一个错误说:
错误:一个`extern条带箱'加载宏必须在条形图root
显然,示例代码加载在宏的模块中,与我不敢相信每个人都直接在根模块中写入宏...
$ b
$ b
添加主要功能做了一个窍门。我的示例代码不需要运行任何东西(只是编译),所以我甚至不打扰添加一个主要功能,但显然添加它将代码放在一个虚拟的条带根中,它接受macro_use。 Yay!
所以我做的只是添加:
//#fn main(){}
I defined a macro in a module, and it works fine. Now, I'm trying to document said macro with an example. Apparently, I need to manually specify the crate line to ask for macros:
/// ```
/// # #[macro_use] extern crate foo;
/// // Some code
/// ```
However, I now get an error saying:
error: an `extern crate` loading macros must be at the crate root
Apparently the example code is loaded in the macro's module, and does not seem compatible with macro_use
...
I can't believe everyone writes macros directly in the root module... right?
Well adding a main function did the trick. My example code did not need to run anything (just compile) so I didn't even bother adding a main function, but apparently adding it puts the code in a virtual "crate root", and it accepts the macro_use. Yay!
So what I did is just add :
/// # fn main() { }
这篇关于如果在模块中定义了宏,如何正确编写宏文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!