#[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 {
/// Terrible.
F3,
/// I fell out of my chair.
F6,
}
assert_eq!(NeverPlay::F3.get_variant_docs(), "Terrible.");
assert_eq!(NeverPlay::F6.get_variant_docs(), "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:
§1. set a default value when doc comments are absent like so:
#[derive(DocumentedVariants)]
#[documented_variants(default = "Still theory.")]
enum OurHeroPlayed {
G4Mate,
OOOMate,
/// Frankly ridiculous.
Bf1g2Mate,
}
assert_eq!(OurHeroPlayed::G4Mate.get_variant_docs(), "Still theory.");
assert_eq!(OurHeroPlayed::OOOMate.get_variant_docs(), "Still theory.");
assert_eq!(
OurHeroPlayed::Bf1g2Mate.get_variant_docs(),
"Frankly ridiculous."
);§2. (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(),
" Or the quality."
);
assert_eq!(Always::Retreat.get_variant_docs(), "Like a Frenchman.");If there are other configuration options you wish to have, please submit an issue or a PR.