#[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 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.
use std::collections::BTreeMap;
use deser::de::{DeserializeDriver, DuplicateKeys};
use deser::Event;
let mut out = None::<BTreeMap<String, u32>>;
let mut driver = DeserializeDriver::new(&mut out);
DuplicateKeys::Error.set(driver.state_mut());
driver.emit(Event::map_start()).unwrap();
for value in [1u64, 2] {
driver.emit("a").unwrap();
driver.emit(value).unwrap();
}
let err = driver.emit(Event::MapEnd).unwrap_err();
assert_eq!(err.message(), "duplicate key in map");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
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
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
Mutably borrows from an owned value. Read more
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
Compare self to
key and return true if they are equal.