Derive Macro documented::DocumentedFields

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

Derive proc-macro for DocumentedFields trait.

§Example

use documented::DocumentedFields;

#[derive(DocumentedFields)]
struct BornIn69 {
    /// Cry like a grandmaster.
    rawr: String,
    explosive: usize,
};

assert_eq!(BornIn69::FIELD_DOCS, [Some("Cry like a grandmaster."), None]);

You can also use get_field_docs to access the fields’ documentation using their names.

assert_eq!(BornIn69::get_field_docs("rawr"), Ok("Cry like a grandmaster."));
assert_eq!(
    BornIn69::get_field_docs("explosive"),
    Err(Error::NoDocComments("explosive".to_string()))
);
assert_eq!(
    BornIn69::get_field_docs("gotcha"),
    Err(Error::NoSuchField("gotcha".to_string()))
);

§Configuration

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

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

#[derive(DocumentedFields)]
#[documented_fields(trim = false)]
struct Frankly {
    ///     Delicious.
    perrier: usize,
    ///     I'm vegan.
    #[documented_fields(trim = true)]
    fried_liver: bool,
}

assert_eq!(Frankly::FIELD_DOCS, [Some("     Delicious."), Some("I'm vegan.")]);

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