Search code examples
macrosrustdocumentationdocumentation-generationrust-crates

How to include documentation for unique match cases in macros?


Is is possible to write documentation for individual match cases of an exported macro.

/// This macro does stuff // this works
#[macro_export]
macro_rules! macro{
    /// Today it's time for cats // error: no rules expected the token `[`
    (cat) => { ... };
    /// Today it's time for dogs // error: no rules expected the token `[`
    (dog) => { ... };
    /// Why not both // error: no rules expected the token `[`
    (cats and dogs) => { ... };
}

Is something like this possible or do I have to do it like this:

/// This macro does stuff
/// `(cat)` - Today it's time for cats
/// `(dog)` - Today it's time for dogs
/// `(cats and dogs)` - Why not both
#[macro_export]
macro_rules! macro{
    (cat) => { ... }; 
    (dog) => { ... };
    (cats and dogs) => { ... };
}

Solution

  • You can't. The only place you can attach documentation to a macro is to the macro as a whole.