rust-cli/confy

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

mclang opened this issue · 1 comments

mclang 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"] }