#documentation #reflection #macro-derive #proc-macro

documented

Traits and derive macros for accessing your type's documentation at runtime

7 unstable releases (3 breaking)

0.4.1 Apr 7, 2024
0.4.0 Apr 1, 2024
0.3.0 Jan 25, 2024
0.2.0 Nov 21, 2023
0.1.2 Jun 7, 2023

#351 in Rust patterns

Download history 55/week @ 2024-01-16 81/week @ 2024-01-23 87/week @ 2024-01-30 80/week @ 2024-02-06 70/week @ 2024-02-13 169/week @ 2024-02-20 239/week @ 2024-02-27 170/week @ 2024-03-05 266/week @ 2024-03-12 232/week @ 2024-03-19 171/week @ 2024-03-26 421/week @ 2024-04-02 290/week @ 2024-04-09 120/week @ 2024-04-16 246/week @ 2024-04-23 177/week @ 2024-04-30

884 downloads per month
Used in 4 crates (3 directly)

MIT license

9KB
51 lines

documented

Traits and derive macros for accessing your type's documentation at runtime

Quick start

use documented::{Documented, DocumentedFields, DocumentedVariants, Error};

/// Trying is the first step to failure.
#[derive(Documented, DocumentedFields, DocumentedVariants)]
enum AlwaysPlay {
    Kb1,
    /// But only if you are white.
    F6,
}

// Documented
assert_eq!(AlwaysPlay::DOCS, "Trying is the first step to failure.");

// DocumentedFields
assert_eq!(
    AlwaysPlay::FIELD_DOCS,
    [None, Some("But only if you are white.")]
);
assert_eq!(
    AlwaysPlay::get_field_docs("Kb1"),
    Err(Error::NoDocComments("Kb1".to_string()))
);
assert_eq!(
    AlwaysPlay::get_field_docs("F6"),
    Ok("But only if you are white.")
);
assert_eq!(
    AlwaysPlay::get_field_docs("Bf1"),
    Err(Error::NoSuchField("Bf1".to_string()))
);

// DocumentedVariants
assert_eq!(
    AlwaysPlay::Kb1.get_variant_docs(),
    Err(Error::NoDocComments("Kb1".to_string()))
);
assert_eq!(
    AlwaysPlay::F6.get_variant_docs(),
    Ok("But only if you are white.")
);

Dependencies

~0.7–1.2MB
~26K SLoC