rust-cli / confy

πŸ›‹ Zero-boilerplate configuration management in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Anything after `HashMap` results in `SerializeTomlError(ValueAfterTable)` error

mclang opened this issue Β· comments

commented

Hello

Unfortunately confy::load(...) fails with SerializeTomlError(ValueAfterTable) error if there is something defined after a HashMap in the configuration struct. For example, my config struct is like this does not work:

#[derive(Debug, Serialize, Deserialize)]
struct Config {
    title:   String,
    api_key: String,
    updated: String,
    centers: std::collections::HashMap<String,String>,
    tasks: Vec<String>,
}

I got it working by swapping the order of centers HashMap and tasks Vector, but I'd rather keep then in the order... Is there any way to make this happen, or is this problem due to how TOML works?

Hello! I apologize this is extremely late but what I am seeing is working right now with v0.6.0 but I might be misunderstanding something.

With the struct:

#[derive(Debug, Serialize, Deserialize)]
struct Config {
    title:   String,
    api_key: String,
    updated: String,
    centers: std::collections::HashMap<String,String>,
    tasks: Vec<String>,
}

I am able to load the following config (generated here by a default function I added):

title = "Hello!"
api_key = "A New One"
updated = "Another"
tasks = [
    "one",
    "two",
    "three",
]

[centers]
key1 = "value1"
key2 = "value2"
key3 = "value3"
Key4 = "new Key here!"

Just fine πŸ˜„

map_toml on ξ‚  main [?] is πŸ“¦ v0.1.0 via πŸ¦€ v1.74.1  ❯
cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/toml_tuple`
MyConfig { title: "Hello!", api_key: "A New One", updated: "Another", centers: {"key2": "value2", "key1": "value1", "key3": "value3", "Key4": "new Key here!"}, tasks: ["one", "two", "three"] }