Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-thinking: Self-describing configuration #339

Open
Tracked by #376
matthiasbeyer opened this issue May 20, 2022 · 3 comments
Open
Tracked by #376

re-thinking: Self-describing configuration #339

matthiasbeyer opened this issue May 20, 2022 · 3 comments

Comments

@matthiasbeyer
Copy link
Member

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    
@dbofmmbt
Copy link
Contributor

dbofmmbt commented May 23, 2022

With a derive-macro, it would probably be possible to print the structure of a config input for any format supported. It could be useful while defining the config struct and easily knowing how to "feed" it.

IDK, just an idea I had 😄

@xinslu
Copy link

xinslu commented Jun 25, 2022

I would love to work on this issue, if possible! I should say I'm still fairly new to Rust, but I think writing a derive macro would be a good first issue!

@matthiasbeyer
Copy link
Member Author

Feel free to try this! A friend of mine (@TheNeikos) implemented it in another project, so I know it is definitively possible! 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants