1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use serde::{Serialize, Serializer};
pub fn stabilize_hashset_serialization<S, V>(set: &HashSet<V>, s: S) -> Result<S::Ok, S::Error> where S: Serializer, V: Ord + serde::Serialize {
let stabilized: BTreeSet<&V> = set.iter().collect();
stabilized.serialize(s)
}
pub fn stabilize_hashmap_serialization<S, K, V>(set: &HashMap<K, V>, s: S) -> Result<S::Ok, S::Error> where S: Serializer, K: Ord + Serialize, V: Serialize {
let stabilized: BTreeMap<&K, &V> = set.iter().collect();
stabilized.serialize(s)
}