object_rainbow/impls/
btree.rs1use std::collections::{BTreeMap, BTreeSet};
2
3use crate::{
4 sequence::{PlainCollection, VecLike},
5 *,
6};
7
8impl<T: InlineOutput> ToOutput for BTreeSet<T> {
9 fn to_output(&self, output: &mut impl Output) {
10 self.iter_to_output(output);
11 }
12}
13
14impl<T: ListHashes> ListHashes for BTreeSet<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 BTreeSet<T> {
21 fn traverse(&self, visitor: &mut impl PointVisitor) {
22 self.iter_traverse(visitor);
23 }
24}
25
26impl<T: ParseInline<I> + Ord, I: ParseInput> Parse<I> for BTreeSet<T> {
27 fn parse(input: I) -> crate::Result<Self> {
28 input.parse_collect()
29 }
30}
31
32impl<T: Tagged> Tagged for BTreeSet<T> {
33 const TAGS: Tags = T::TAGS;
34}
35
36impl<T: ByteOrd + InlineOutput> ByteOrd for BTreeSet<T> {
37 fn bytes_cmp(&self, other: &Self) -> Ordering {
38 self.iter_bytes_cmp(other)
39 }
40}
41
42impl<T> PlainCollection for BTreeSet<T> {}
43impl<T> VecLike for BTreeSet<T> {}
44
45impl<K: InlineOutput, V: InlineOutput> ToOutput for BTreeMap<K, V> {
46 fn to_output(&self, output: &mut impl Output) {
47 self.iter_to_output(output);
48 }
49}
50
51impl<K: ListHashes, V: ListHashes> ListHashes for BTreeMap<K, V> {
52 fn list_hashes(&self, f: &mut impl FnMut(Hash)) {
53 self.iter_list_hashes(f);
54 }
55}
56
57impl<K: Topological, V: Topological> Topological for BTreeMap<K, V> {
58 fn traverse(&self, visitor: &mut impl PointVisitor) {
59 self.iter_traverse(visitor);
60 }
61}
62
63impl<K: ParseInline<I> + Ord, V: ParseInline<I>, I: ParseInput> Parse<I> for BTreeMap<K, V> {
64 fn parse(input: I) -> crate::Result<Self> {
65 input.parse_collect()
66 }
67}
68
69impl<K: Tagged, V: Tagged> Tagged for BTreeMap<K, V> {
70 const TAGS: Tags = Tags(&[], &[&K::TAGS, &V::TAGS]);
71}
72
73impl<K: ByteOrd + InlineOutput, V: ByteOrd + InlineOutput> ByteOrd for BTreeMap<K, V> {
74 fn bytes_cmp(&self, other: &Self) -> Ordering {
75 self.iter_bytes_cmp(other)
76 }
77}
78
79impl<K, V> PlainCollection for BTreeMap<K, V> {}
80impl<K, V> VecLike for BTreeMap<K, V> {}
81
82impl<K: Ord> Equivalent<BTreeMap<K, ()>> for BTreeSet<K> {
83 fn into_equivalent(self) -> BTreeMap<K, ()> {
84 self.into_iter().map(|k| (k, ())).collect()
85 }
86
87 fn from_equivalent(object: BTreeMap<K, ()>) -> Self {
88 object.into_iter().map(|(k, ())| k).collect()
89 }
90}