From 4a3277068b15d241c8f88d4897d2af4e7f3290b2 Mon Sep 17 00:00:00 2001 From: Campbell He Date: Tue, 21 Feb 2023 11:15:13 +0800 Subject: [PATCH] Use IndexSet in preserve_order --- schemars/src/flatten.rs | 5 ++++- schemars/src/lib.rs | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/schemars/src/flatten.rs b/schemars/src/flatten.rs index 35a734fa..fee9a6aa 100644 --- a/schemars/src/flatten.rs +++ b/schemars/src/flatten.rs @@ -139,7 +139,10 @@ where } } -impl Merge for Set { +impl Merge for Set +where + T: std::hash::Hash + Ord, +{ fn merge(mut self, other: Self) -> Self { self.extend(other); self diff --git a/schemars/src/lib.rs b/schemars/src/lib.rs index 2094c428..915f5318 100644 --- a/schemars/src/lib.rs +++ b/schemars/src/lib.rs @@ -295,9 +295,13 @@ pub type Map = std::collections::BTreeMap; pub type Map = indexmap::IndexMap; /// The set type used by schemars types. /// -/// Currently a `BTreeSet`, but this may change to a different implementation +/// Currently a `BTreeSet` or `IndexSet`, but this may change to a different implementation /// with a similar interface in a future version of schemars. +/// The `IndexSet` will be used when the `preserve_order` feature flag is set. +#[cfg(not(feature = "preserve_order"))] pub type Set = std::collections::BTreeSet; +#[cfg(feature = "preserve_order")] +pub type Set = indexmap::IndexSet; /// A view into a single entry in a map, which may either be vacant or occupied. //