Deserialize field to HashMap<String, MyStruct>

52 views Asked by At

I have a TOML file like this:

[versions."4.2-stable"]
path = "..."

[versions."3.5-rc3"]
path = "..."

# etc.

And a struct like this:

#[derive(serde::Deserialize, serde::Serialize)]
pub struct Versions {
    pub versions: SomeMapType<String, Version>,
}

#[derive(serde::Deserialize, serde::Serialize)]
pub struct Version {
    pub path: String,
}

I want to be able to deserialize that TOML into my struct, but the problem is that i'm not sure what type to use in place of SomeMapType. I tried using ahash::AHashMap and toml::map::Map, but neither worked and result in " doesn't implement Deserialize" errors. Maybe some custom logic is needed? Any help is appreciated!

0

There are 0 answers