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

Add builder pattern for Partial #43

Open
synek317 opened this issue Dec 2, 2024 · 0 comments
Open

Add builder pattern for Partial #43

synek317 opened this issue Dec 2, 2024 · 0 comments

Comments

@synek317
Copy link

synek317 commented Dec 2, 2024

It would be useful when working with multiple "preloaded" sources, e.g.

#[derive(Config)]
struct Cfg {
    foo: usize,
    bar: String,
}

fn main() {
    let cfg = Cfg::builder().preloaded(Cfg::partial().foo(42)).load();
}

Perhaps makes more sense in a more complex example

fn do_something(cli_args: Args, global_config: GlobalConfig) {
    let cfg = Cfg::builder()
        .preloaded(Cfg::partial().foo(cli_args.foo).bar(cli_args.bar))
        .env()
        .preloaded(Cfg::partial().foo(global_config.my_app.foo).qux(global_config.global.qux))
        .load()?;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant