#[non_exhaustive]pub enum DuplicateKeys {
Last,
First,
Error,
}Expand description
What happens if a key is given more than once.
JSON objects can contain the same key more than once and query strings
commonly repeat keys. Where a single value is expected (the field of a
struct or an entry of a map) the policy decides what happens. It’s an
extension value, usually configured in the Context
(or in the State, see set). The default is
Error: if the same key could mean different values to
different parsers (a proxy might use the first value, the application the
last) the input is rejected. Formats can have other defaults (query
strings and environment variables use the last value), which the
context overrides.
use std::collections::BTreeMap;
use deser::de::DuplicateKeys;
use deser::Context;
type Map = BTreeMap<String, u32>;
let input = r#"{"a": 1, "a": 2}"#;
let err = deser_json::from_str::<Map>(input).unwrap_err();
assert_eq!(err.message(), "duplicate key in map");
let config = deser_json::DeserializerConfig::builder()
.context(Context::with(DuplicateKeys::Last))
.build();
assert_eq!(config.from_str::<Map>(input).unwrap()["a"], 2);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Last
The last value is used.
First
The first value is used, later ones are ignored.
Error
Duplicate keys are rejected.
Implementations§
Source§impl DuplicateKeys
impl DuplicateKeys
Sourcepub fn of(state: &State) -> DuplicateKeys
pub fn of(state: &State) -> DuplicateKeys
Returns the policy of a deserialization.
Sourcepub fn set_default(self, state: &mut State)
pub fn set_default(self, state: &mut State)
Sets the policy unless the state or the context has one.
Formats use this for their default (see State::set_default).
Trait Implementations§
Source§impl Clone for DuplicateKeys
impl Clone for DuplicateKeys
impl Copy for DuplicateKeys
Source§impl Debug for DuplicateKeys
impl Debug for DuplicateKeys
Source§impl Default for DuplicateKeys
impl Default for DuplicateKeys
impl Eq for DuplicateKeys
Source§impl PartialEq for DuplicateKeys
impl PartialEq for DuplicateKeys
impl StructuralPartialEq for DuplicateKeys
Auto Trait Implementations§
impl Freeze for DuplicateKeys
impl RefUnwindSafe for DuplicateKeys
impl Send for DuplicateKeys
impl Sync for DuplicateKeys
impl Unpin for DuplicateKeys
impl UnsafeUnpin for DuplicateKeys
impl UnwindSafe for DuplicateKeys
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.