Canop / deser-hjson

A Serde 1.0 compatible Rust deserializer for Hjson

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature suggestion: alternativer handling of nonexistent and extra fields

DanielT opened this issue · comments

I just looked at deser-hjson, ran the example code, etc.
While playing around with it I noticed the following:

  • if I add extra fields that are not defined in the Rust data type, e.g. "nonexistent: 0", then there is no error
  • if I omit a key that is defined in the datatype then this is an error

This is basically the opposite of what I would want for the config file format for a program.
The way I would expect that to work is that missing fields in the config file would simply have default values.
On the other hand additional/unspecified fields indicate either a typo or a misunderstanding of the documentation, and the user should be notified about this.

Would you consider it to be in-scope to add such a mode of operation to hjson-deser?

When you want a key to be optional, you define it with an option. See this example. This works the same for other deserializers.

This makes it possible to have the structure's validity checked: optional fields are the only ones that can be missing.

Right, I somehow overlooked that the example already showed how to use Option<>.
I also found out how to make deserializing strict, so there is no feature request after all.

Thanks for the help.