Skip to content

re-thinking: Self-describing configuration #339

Open
@matthiasbeyer

Description

@matthiasbeyer

I do work with @TheNeikos in an open source project where we introduced "self-describing" configuration types.

That means that we provided a derive macro that could be used on config types so that fetching an explanation of what that type meant is possible. The derive-macro used the doc comments for that.

We should explore how it would be possible to add something like this to this crate.


As a quick example for some imaginary crate:

#[derive(Debug, config::ConfigDescription)]
struct MyConfig {
    /// The URL to fetch data from
    url: url::Url,

    /// The verbosity while fetching
    verbosity: Verbosity,
}

#[derive(Debug, config::ConfigDescription)]
enum Verbosity {
    /// be loud
    Loud,
    /// be louder than normal
    Louder,
    /// be as loud as possible
    Loudest,
}

// somewhere:
MyConfig::config_description() // returns ConfigDescription object that can be rendered for the user in a nice way

Resuling in approximately this output:

[table]

The URL to fetch data from
url: An URL
    An UTF-8 encoded String

The verbosity while fetching
verbosity: Verbosity
    one of:
        "load" - be loud
        "louder" - be louder than normal
        "loudest" - be as loud as possible    

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions