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

How to convert `HashMap<String, T>` to configparser ini String? #35

Closed lcmgh closed 4 months ago

lcmgh commented 1 year ago

I would like to save a config file with data sourced from HashMap<String, T>. Is there a easy way to construct Ini and serialize it to a String?

QEDK commented 1 year ago

I would like to save a config file with data sourced from HashMap<String, T>. Is there a easy way to construct Ini and serialize it to a String?

Two ways, consider T as Option<String> and serialize to HashMap<String("default"), HashMap<String, Option<String>>, which outputs a flat ini-file with no header (the default header is modifiable). Second is to consider T as HashMap<String, Option<String>> in which case, each string in the original hashmap becomes a header.