#[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
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
impl Clone for DuplicateKeyPolicy
Source§fn clone(&self) -> DuplicateKeyPolicy
fn clone(&self) -> DuplicateKeyPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more