[][src]Crate structdoc

Extract documentation out of types and make use of it at runtime.

The StructDoc trait describes types which know their own documentation at runtime. It can be derived (see the StructDoc documentation for deriving details). The Documentation is a type holding the actual documentation.

Motivation

Sometimes, an application needs some structured input from the user ‒ configuration, input files, etc. Therefore, the format needs to be documented somehow. But doing so manually has several disadvantages:

This crate tries to help with that ‒ it allows extracting doc strings and composing them together to form the documentation automatically, using procedural derive. The structure is guaranteed to match and the documentation strings are much more likely to be updated, as they are close to the actual definitions being changed.

It is able to use both its own and serde's attributes, because serde is very commonly used to read the structured data.

Examples

use std::num::NonZeroU32;

use serde_derive::Deserialize;
use structdoc::StructDoc;

#[derive(Deserialize, StructDoc)]
struct Point {
    /// The horizontal position.
    x: i32,

    /// The vertical position.
    y: i32,
}

#[derive(Deserialize, StructDoc)]
struct Circle {
    // Will flatten both on the serde side and structdoc, effectively creating a structure with
    // 3 fields for both of them.
    #[serde(flatten)]
    center: Point,

    /// The diameter of the circle.
    diameter: NonZeroU32,
}

println!("{}", Circle::document());

TODO

This crate is young and has some missing things:

In other words, let this crate generate the documentation, but skim the result before shipping to make sure it is correct and makes sense. Pull requests to fix bugs are indeed welcome.

Structs

Documentation

A representation of documentation.

Field

A documentation node with actual documentation text.

Flags

Flags on nodes of Documentation.

Enums

Arity

An arity of an container.

Tagging

A tagging of an enum.

Traits

StructDoc

Types that can provide their own documentation at runtime.

Type Definitions

Text

Text representation.

Derive Macros

StructDoc