在定义表单的某些元组结构时,我有几个宏来减少样板:
macro_rules! new_type (($name:ident, $bytes:expr) => (
pub struct $name(pub [u8; $bytes]);
// some common operations on $name
));
Run Code Online (Sandbox Code Playgroud)
但是,我还要记录这些新结构.如果我能在宏调用之前编写我的文档,最好的事情就是.
/// A certain type
new_type!(CertainType, 42);
Run Code Online (Sandbox Code Playgroud)
但是,Rust不会生成CertainType发生这种情况的文档.
另一种(不那么灵活)替代方案是做类似的事情:
macro_rules! new_type (($name:ident, $bytes:expr) => (
/// Some more generic documentation for $name
pub struct $name(pub [u8; $bytes]);
// some common operations on $name
));
Run Code Online (Sandbox Code Playgroud)
但是,在执行此操作时,Rust宏系统不会$name在文档注释中展开令牌.剩下的唯一选择是在宏中编写非常通用的文档,但这会导致我的库文档记录得比它更糟糕.
您对此有何建议?对我来说最好的解决方案是能够为每个宏调用编写特定的文档,但如果不可能,我会很感激有关如何在文档注释中扩展标记的提示.