Debian Codegraph @

src/data_format/utils.rs

raw symbols SCIP
1 //! Common utilities associated with serialization and deserialization of the `Engine` data into
2 //! binary formats.
3
4 use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
5
6 use serde::{Serialize, Serializer};
7
8 /// Forces a `HashSet` to be serialized with a stable ordering by temporarily representing it as a
9 /// `BTreeSet`.
10 pub fn stabilize_hashset_serialization<S, V>(set: &HashSet<V>, s: S) -> Result<S::Ok, S::Error>
11 where
12 S: Serializer,
13 V: Ord + serde::Serialize,
14 {
15 let stabilized: BTreeSet<&V> = set.iter().collect();
16 stabilized.serialize(s)
17 }
18
19 /// Forces a `HashMap` to be serialized with a stable ordering by temporarily representing it as a
20 /// `BTreeMap`.
21 pub fn stabilize_hashmap_serialization<S, K, V>(
22 set: &HashMap<K, V>,
23 s: S,
24 ) -> Result<S::Ok, S::Error>
25 where
26 S: Serializer,
27 K: Ord + Serialize,
28 V: Serialize,
29 {
30 let stabilized: BTreeMap<&K, &V> = set.iter().collect();
31 stabilized.serialize(s)
32 }