#[non_exhaustive]pub enum UnknownFields {
Ignore,
Error,
Collect(IgnoredFields),
}Expand description
What happens with keys of structs that no field takes.
Derived structs ignore keys they do not know by default. This policy
changes that for all structs of a deserialization, while
#[deser(deny_unknown_fields)] rejects unknown keys for a single type
regardless of the policy. It’s an extension value, usually configured
in the Context (or in the State of a single
deserialization, see set). To collect the unknown keys
of a single deserialization see IgnoredFields.
Only the struct that the key is given to decides: flattened fields are
asked if they take a key first (see
value_for_key), so a key is only
unknown if neither the struct nor any of its flattened fields take it.
use deser::de::UnknownFields;
use deser::{Context, Deserialize};
#[derive(Deserialize, Debug)]
struct Config {
name: String,
}
let config = deser_json::DeserializerConfig::builder()
.context(Context::with(UnknownFields::Error))
.build();
let err = config
.from_str::<Config>(r#"{"name": "demo", "nmae": "demo"}"#)
.unwrap_err();
assert_eq!(err.message(), "unknown field `nmae`, expected `name`");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Ignore
Unknown keys are ignored.
Error
Unknown keys are rejected.
Collect(IgnoredFields)
Unknown keys are ignored but reported to a IgnoredFields.
The collector is shared, so this is meant for a single
deserialization (see IgnoredFields).