Open togetherwithasteria opened 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.
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 ^^
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)
}
}
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.
Aaa thank you so much!
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: @.***>
Hi! Can we have serde support in configparser?