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

Expose coalesce module #74

Open
fabianfreyer opened this issue Jun 22, 2023 · 3 comments
Open

Expose coalesce module #74

fabianfreyer opened this issue Jun 22, 2023 · 3 comments

Comments

@fabianfreyer
Copy link

fabianfreyer commented Jun 22, 2023

The figment::coalesce::Coalescible trait seems very helpful when writing providers, any chance to make that pub?

@SergioBenitez
Copy link
Owner

SergioBenitez commented Jul 7, 2023

Which things would be helpful? And how do you plan to use them?

@fabianfreyer
Copy link
Author

Right now, I'm just copying the whole Coalescible implementation, so it would be helpful if I could import that instead of copying it. I'm using it in a Provider to build a nested Dict from a mapping of key, value pairs where the keys are dot- or underscore-separated paths:

for (k, v) in self.data.iter().map(|(k, v)| {
    let key = k.to_ascii_lowercase().replace('_', ".");
    (key, v.to_owned())
}) {
    let nested_dict: std::collections::BTreeMap<String, figment::value::Value> =
        nest(k.as_str(), v.parse().expect("infallible"))
            .into_dict()
            .expect("key is non-empty: must have dict");

    dict = dict.merge(nested_dict);
}

let profile = Profile::default();
Ok(profile.collect(dict))

@SergioBenitez
Copy link
Owner

I do eventually want to expose the implementations underling the module in some form, but I'm not sure exposing it directly is the right way. I'll give this some more thought and post an update later day.

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

2 participants