Expand description
forgiving.rs: the deserializer that applies normalize to a plugin’s own
config, without the plugin having to know.
The host cannot simply normalize the keys it was given. serde matches field
names by exact comparison against a set fixed at compile time by
rename_all, rename and alias, so rewriting max-connections to
maxconnections would stop matching a rename_all = "kebab-case" struct,
and deny_unknown_fields would turn the miss into a hard error. The host
also cannot know a plugin’s field names in advance, and for a WASM guest it
never will.
But serde hands them over at the moment of use.
Deserializer::deserialize_struct receives the declared field list, and
deserialize_enum the declared variants. So this deserializer normalizes to
match and then rewrites the key to the plugin’s own spelling before the
derive ever sees it. The plugin’s struct, its rename_all and its
deny_unknown_fields behave exactly as written, aliases keep working, and
an option nobody declared still reaches the plugin to be rejected there.
Everything else delegates to serde_json, so a type with a hand-written
Deserialize (rate’s Interval, which asks for deserialize_any and
parses "500ms" itself) is untouched.
Structs§
- Forgiving
- A
serde_json::Valuethat matches identifiers the way the rest of tocat does.