9 unstable releases (3 breaking)

new 0.4.3 May 27, 2024
0.4.2 May 27, 2024
0.4.1 Apr 7, 2024
0.3.0 Jan 25, 2024
0.1.2 Jun 7, 2023

#8 in #documented

Download history 104/week @ 2024-02-04 52/week @ 2024-02-11 160/week @ 2024-02-18 226/week @ 2024-02-25 176/week @ 2024-03-03 232/week @ 2024-03-10 301/week @ 2024-03-17 76/week @ 2024-03-24 406/week @ 2024-03-31 378/week @ 2024-04-07 170/week @ 2024-04-14 212/week @ 2024-04-21 217/week @ 2024-04-28 108/week @ 2024-05-05 240/week @ 2024-05-12 247/week @ 2024-05-19

832 downloads per month
Used in 5 crates (via documented)

MIT license

9KB
171 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

~290–740KB
~18K SLoC