QEDK / configparser-rs

A simple configuration parsing utility with no dependencies built on Rust.
https://crates.io/crates/configparser
Other
66 stars 21 forks source link

Serde support? #33

Open togetherwithasteria opened 2 years ago

togetherwithasteria commented 2 years ago

Hi! Can we have serde support in configparser?

QEDK commented 2 years ago

Hi! Can we have serde support in configparser?

The question isn't can but why? If you have a use-case for it, I think we can think about possibilities as to why we should be adding it as a feature.

togetherwithasteria commented 2 years ago

Hi! Can we have serde support in configparser?

The question isn't can but why? If you have a use-case for it, I think we can think about possibilities as to why we should be adding it as a feature.

Well, I wanted to have the data be represented as hard-typed structs but doing that without Serde seems to be verbosyy ^^

https://github.com/waylovely-project/flara-shop/blob/eeefb5f6f3c9a23e0b21618eac4f2c62acfbae33/flarapak/src/schemas/remote.rs

hansl commented 1 year ago

Yes. Hard typed structures is also a use case for us. This library is actually very hard to use and very verbose without some kind of derive based structure deserialization. Serde is just the easiest framework to implement this, and already a pseudo-standard in the Rust ecosystem.

What I want is something like:

#[derive(Deserialize)] // Could be from configparser, but would prefer serde.
pub struct Config {
  pub some_config: String,
  pub some_other_config: Option<u32>,
}

impl Config {
  pub fn load(path: impl AsRef<Path>) -> Result<Self, HereBeErrType> {
    let str = std::fs::read_to_string(path)?;
    configparser::parse::<Self>(&str)
  }
}
QEDK commented 1 year ago

Yes. Hard typed structures is also a use case for us. This library is actually very hard to use and very verbose without some kind of derive based structure deserialization. Serde is just the easiest framework to implement this, and already a pseudo-standard in the Rust ecosystem.

What I want is something like:

#[derive(Deserialize)] // Could be from configparser, but would prefer serde.
pub struct Config {
  pub some_config: String,
  pub some_other_config: Option<u32>,
}

impl Config {
  pub fn load(path: impl AsRef<Path>) -> Result<Self, HereBeErrType> {
    let str = std::fs::read_to_string(path)?;
    configparser::parse::<Self>(&str)
  }
}

The work is now underway, I think as the wider ecosystem expands to use serde, it only makes sense to provide native support.

togetherwithasteria commented 1 year ago

Aaa thank you so much!

QEDK commented 1 year ago

An easy way might be to use serde_json, parse our unparsed string and return the generic type? It is inefficient but doesn't require rebuilding the wheel. ~~

On Mon, 3 Jul 2023 at 01:46, natasria @.***> wrote:

Aaa thank you so much!

— Reply to this email directly, view it on GitHub https://github.com/QEDK/configparser-rs/issues/33#issuecomment-1616835995, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJWRQRB3ZULUCGN6YII6ZLXOHT3DANCNFSM6AAAAAARMAYPOY . You are receiving this because you commented.Message ID: @.***>