Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize part struct part HashMap #1055

Closed
daschl opened this issue Sep 12, 2017 · 1 comment
Closed

Deserialize part struct part HashMap #1055

daschl opened this issue Sep 12, 2017 · 1 comment

Comments

@daschl
Copy link

daschl commented Sep 12, 2017

Hi,

I haven't found any documentation on this one, so I wanted to file an enhancement request - if this is already possible please disregard.

So my objective is I'm reading in a toml/json config file and parts of the structure are well known/mandatory but others are optional and. So I want to end up with something like

#[derive(Deserialize)]
struct Config {
  name: String,
  age: u8,
  all_the_rest: HashMap<String, Any> // I guess where any is something like toml::Value or serde_json::Value
}

So when I read the config in, all the attributes that are not name or age get fed into the all_the_rest hashmap instead of being ignored.

This has the related question of the Any in the value - would it be possible to make this generic over the input format, so I don't need to actually store a toml::Value or a serde_json::Value `?

@daschl
Copy link
Author

daschl commented Sep 12, 2017

ah this is covered in #941 it seems. closing as dup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants