Is there a way to hide a macro pattern from docs?

2019-06-15 21:03发布

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

macro implementation hidden

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) };
}

1条回答
Fickle 薄情
2楼-- · 2019-06-15 21:32

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) );
}

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.

查看更多
登录 后发表回答