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

INI format support #72

Closed
jpmckinney opened this issue May 28, 2023 · 3 comments
Closed

INI format support #72

jpmckinney opened this issue May 28, 2023 · 3 comments

Comments

@jpmckinney
Copy link

jpmckinney commented May 28, 2023

I use INI.

(If you're wondering why, I prefer to spare my (often non-technical) users from having to worry about significant whitespace (YAML), syntax errors and escape characters (JSON, TOML, XML, YAML), nesting errors (XML, YAML) – and I want to provide in-line documentation via comments (not in JSON).)

@SergioBenitez
Copy link
Owner

I'd be happy to add support for INI. Last I checked, there was no obvious candidate for a serde support crate we could use. Has this changed? If so, I'd be happy to accept a PR. The implementation is almost trivial as it's a simple implementation of the Format trait already automated by an existing macro (this is how the Json and Toml implementations are generated).

@jpmckinney
Copy link
Author

config-rs uses https://docs.rs/rust-ini/latest/ini/, but serde support is an open issue zonyitoo/rust-ini#40

I haven't looked at https://github.com/arcnmx/serde-ini

@SergioBenitez
Copy link
Owner

SergioBenitez commented May 31, 2023

Figment is built around serde, so the crate must support serde, and support it rather well. serde-ini hasn't seen a commit in a couple of years, and a few of its open issues call for features that seem like those one would expect, like arcnmx/serde-ini#8, so I'm not sure it's developed enough for us to include it directly. If you find another library, please feel free to reopen this issue or submit a PR.

Otherwise, please note that you can trivially implement support for INI entirely outside of Figment by implementing the Format trait. An implementation using serde-ini would look like this:

struct Ini;

impl Format for Ini {
    type Error = serde_ini::de::Error;

    const NAME: &'static str = "INI";

    fn from_str<'de, T: DeserializeOwned>(string: &'de str) -> Result<T, Self::Error> {
        serde_ini::de::from_str(string)
    }
}

Then you can use it just like Toml or Json:

use figment::providers::Format;

Figment::new()
    .merge(Ini::file("myapp.conf"))
    .join(Ini::file("defaults.conf"))

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