Skip to main content

DuplicateKeyPolicy

Enum DuplicateKeyPolicy 

Source
#[non_exhaustive]
pub enum DuplicateKeyPolicy { Error, FirstWins, LastWins, PassThrough, }
Expand description

Duplicate key handling policy for mappings.

Except with Self::PassThrough, YAML integer keys are compared by their parsed integer value, so 0xB and 11 are duplicates even when the target key type is String. The retained key preserves its original spelling when deserialized into a string. Merge expansion always uses YAML key identity.

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.
§

Error

Error out on encountering a duplicate key.

§

FirstWins

First key wins: later duplicate pairs are skipped (key+value are consumed and ignored).

§

LastWins

Last key wins: retain the later value. Struct fields are buffered and collapsed before Serde sees them. Maps stream until an integer-containing key requires numeric comparison, then buffer the remaining entries to retain the last key’s original spelling and value.

§

PassThrough

Forward repeated explicit mapping entries to the receiving Serde visitor.

This matches serde_yaml’s visitor-driven handling of explicit entries: derived structs reject repeated fields, standard maps keep the last value, and custom visitors decide whether to reject, replace, or retain duplicates. Integer-equivalent keys such as 0xB and 11 are also forwarded separately.

Merge expansion still follows MergeKeyPolicy and suppresses overridden entries. Repeated keys within a merge source retain the first entry. Use MergeKeyPolicy::AsOrdinary to forward literal << entries as well.

This is a permissive extension: YAML requires unique mapping keys. Self::Error remains the default.

Trait Implementations§

Source§

impl Clone for DuplicateKeyPolicy

Source§

fn clone(&self) -> DuplicateKeyPolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DuplicateKeyPolicy

Source§

impl Debug for DuplicateKeyPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.