有没有办法在文档中隐藏宏模式? [英] Is there a way to hide a macro pattern from docs?

查看:131
本文介绍了有没有办法在文档中隐藏宏模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Rust 1.6.0开始,生成的文档隐藏了每个宏模式的实现:

As of Rust 1.6.0, the generated documentation hides the implementation of each macro pattern:

有没有一种方法可以隐藏由Cargo生成的文档中的某些模式?

Is there a way to hide some of the patterns from the Cargo-generated docs?

macro_rules! mc {
    // hide this entire pattern
    (@impl, $arg:expr) => { 42 + $arg };
    // but not this one
    ($arg:expr) => { mc!(@impl, $arg) };
}

推荐答案

我猜这是最佳解决方案:

I guess this is the optimum solution:

/// Not meant to be called directly
#[doc(hidden)]
#[macro_export]
macro_rules! hidden {
    ( $hidden_rule1:expr ) => { ... };
    ( $hidden_rule2:expr ) => { ... };
    ...
}

#[macro_export]
macro_rules! public {
    ( $public:expr ) => ( hidden!($public) );
}

这使用一个单独的hidden宏(可能需要将其公开),但它不是文档的一部分.所有应隐藏的规则都将被隐藏,而公共规则将在文档的一部分public宏中可见.

This uses a separate hidden macro (which will probably need to be public) but which is not part of the documentation. All the rules that should be hidden will be hidden and the public one will be visible in the public macro which is part of the documentation.

这篇关于有没有办法在文档中隐藏宏模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆