configparser-rs icon indicating copy to clipboard operation
configparser-rs copied to clipboard

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

Open lcmgh opened this issue 2 years ago • 1 comments

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?

lcmgh avatar Mar 01 '23 08:03 lcmgh

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.

QEDK avatar Apr 03 '23 19:04 QEDK