Skip to main content

object_rainbow/impls/
indexmap.rs

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