Derive Macro documented::DocumentedVariants

source ·
#[derive(DocumentedVariants)]
{
    // Attributes available to this derive:
    #[documented_variants]
}
Expand description

Derive proc-macro for DocumentedVariants trait.

§Example

use documented::{DocumentedVariants, Error};

#[derive(DocumentedVariants)]
enum NeverPlay {
    F3,
    /// I fell out of my chair.
    F6,
}

assert_eq!(
    NeverPlay::F3.get_variant_docs(),
    Err(Error::NoDocComments("F3".into()))
);
assert_eq!(
    NeverPlay::F6.get_variant_docs(),
    Ok("I fell out of my chair.")
);

§Configuration

With the customise feature enabled, you can customise this macro’s behaviour using the #[documented_variants(...)] attribute. Note that this attribute works on both the container and each individual variant, with the per-variant configurations overriding container configurations, which override the default.

Currently, you can (selectively) disable line-trimming like so:

#[derive(DocumentedVariants)]
#[documented_variants(trim = false)]
enum Always {
    ///     Or the quality.
    SacTheExchange,
    ///     Like a Frenchman.
    #[documented_variants(trim = true)]
    Retreat,
}
assert_eq!(
    Always::SacTheExchange.get_variant_docs(),
    Ok("     Or the quality.")
);
assert_eq!(Always::Retreat.get_variant_docs(), Ok("Like a Frenchman."));

If there are other configuration options you wish to have, please submit an issue or a PR.