Skip to main content

object_rainbow/impls/
indexmap.rs

1use indexmap::{IndexMap, IndexSet};
2
3use crate::*;
4
5impl<T: InlineOutput> ToOutput for IndexSet<T> {
6    fn to_output(&self, output: &mut impl Output) {
7        self.iter_to_output(output);
8    }
9}
10
11impl<T: ListHashes> ListHashes for IndexSet<T> {
12    fn list_hashes(&self, f: &mut impl FnMut(Hash)) {
13        self.iter_list_hashes(f);
14    }
15}
16
17impl<T: Topological> Topological for IndexSet<T> {
18    fn traverse(&self, visitor: &mut impl PointVisitor) {
19        self.iter_traverse(visitor);
20    }
21}
22
23impl<T: ParseInline<I> + Eq + std::hash::Hash, I: ParseInput> Parse<I> for IndexSet<T> {
24    fn parse(input: I) -> crate::Result<Self> {
25        input.parse_collect()
26    }
27}
28
29impl<T: Tagged> Tagged for IndexSet<T> {
30    const TAGS: Tags = T::TAGS;
31}
32
33impl<K: InlineOutput, V: InlineOutput> ToOutput for IndexMap<K, V> {
34    fn to_output(&self, output: &mut impl Output) {
35        self.iter_to_output(output);
36    }
37}
38
39impl<K: ListHashes, V: ListHashes> ListHashes for IndexMap<K, V> {
40    fn list_hashes(&self, f: &mut impl FnMut(Hash)) {
41        self.iter_list_hashes(f);
42    }
43}
44
45impl<K: Topological, V: Topological> Topological for IndexMap<K, V> {
46    fn traverse(&self, visitor: &mut impl PointVisitor) {
47        self.iter_traverse(visitor);
48    }
49}
50
51impl<K: ParseInline<I> + Eq + std::hash::Hash, V: ParseInline<I>, I: ParseInput> Parse<I>
52    for IndexMap<K, V>
53{
54    fn parse(input: I) -> crate::Result<Self> {
55        input.parse_collect()
56    }
57}
58
59impl<K: Tagged, V: Tagged> Tagged for IndexMap<K, V> {
60    const TAGS: Tags = Tags(&[], &[&K::TAGS, &V::TAGS]);
61}
62
63impl<K: Eq + std::hash::Hash> Equivalent<IndexMap<K, ()>> for IndexSet<K> {
64    fn into_equivalent(self) -> IndexMap<K, ()> {
65        self.into_iter().map(|k| (k, ())).collect()
66    }
67
68    fn from_equivalent(object: IndexMap<K, ()>) -> Self {
69        object.into_iter().map(|(k, ())| k).collect()
70    }
71}