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

Serde support? #33

Open
togetherwithasteria opened this issue Oct 22, 2022 · 6 comments
Open

Serde support? #33

togetherwithasteria opened this issue Oct 22, 2022 · 6 comments

Comments

@togetherwithasteria
Copy link

Hi! Can we have serde support in configparser?

@QEDK
Copy link
Owner

QEDK commented Oct 22, 2022

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
Copy link
Author

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
Copy link

hansl commented Jun 29, 2023

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
Copy link
Owner

QEDK commented Jul 2, 2023

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
Copy link
Author

Aaa thank you so much!

@QEDK
Copy link
Owner

QEDK commented Jul 3, 2023 via email

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

3 participants