1#[derive(Debug, Clone)]
6pub struct OrderedSet<V: Debug + Clone + Eq + Hash + Serialize + Deserialize>(OrderMap<V, ()>);
7
8impl<V: Debug + Clone + Eq + Hash + Serialize + Deserialize> Serialize for OrderedSet<V>
9{
10 fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
11 {
12 let ordered: Vec<V> = self.0.keys().map(|key| key.clone()).collect();
13 ordered.serialize(serializer)
14 }
15}
16
17impl<V: Debug + Clone + Eq + Hash + Serialize + Deserialize> Deserialize for OrderedSet<V>
18{
19 fn deserialize<D: Deserializer>(deserializer: D) -> Result<Self, D::Error>
20 {
21 let mut ordered = Vec::<V>::deserialize(deserializer)?;
22 let mut map = OrderMap::with_capacity(ordered.len());
23 for value in ordered.drain(..)
24 {
25 map.insert(value, ());
26 }
27 Ok(OrderedSet(map))
28 }
29}
30
31impl<V: Debug + Clone + Eq + Hash + Serialize + Deserialize> Default for OrderedSet<V>
32{
33 #[inline(always)]
34 fn default() -> Self
35 {
36 OrderedSet(Default::default())
37 }
38}