1pub trait AsImOrdMap<K: Ord + Clone, V: Clone>: Clone {
2 fn insert(&mut self, k: K, v: V) -> Option<V>;
3 fn to_inserted(&self, k: K, v: V) -> (Self, Option<V>) {
4 let mut new = self.clone();
5
6 let res = new.insert(k, v);
7
8 (new, res)
9 }
10
11 fn remove<BK: Ord>(&mut self, k: &BK) -> Option<V>
12 where
13 K: std::borrow::Borrow<BK>;
14 fn to_removed<BK: Ord>(&mut self, k: &BK) -> (Self, Option<V>)
15 where
16 K: std::borrow::Borrow<BK>,
17 {
18 let mut new = self.clone();
19
20 let res = new.remove(k);
21
22 (new, res)
23 }
24
25 fn remove_with_key<BK: Ord>(&mut self, k: &BK) -> Option<(K, V)>
26 where
27 K: std::borrow::Borrow<BK>;
28 fn to_removed_with_key<BK: Ord>(&mut self, k: &BK) -> (Self, Option<(K, V)>)
29 where
30 K: std::borrow::Borrow<BK>,
31 {
32 let mut new = self.clone();
33
34 let res = new.remove_with_key(k);
35
36 (new, res)
37 }
38
39 fn to_extended<I: IntoIterator<Item = (K, V)>>(&self, iter: I) -> Self
40 where
41 Self: Extend<(K, V)>,
42 {
43 let mut new = self.clone();
44
45 new.extend(iter);
46
47 new
48 }
49
50 fn iter_clone(&self) -> Self::IntoIter
51 where
52 Self: IntoIterator,
53 {
54 self.clone().into_iter()
55 }
56}
57
58impl<K: Ord + Clone, V: Clone> AsImOrdMap<K, V> for im_rc::OrdMap<K, V> {
59 fn insert(&mut self, k: K, v: V) -> Option<V> {
60 im_rc::OrdMap::insert(self, k, v)
61 }
62
63 fn remove<BK: Ord>(&mut self, k: &BK) -> Option<V>
64 where
65 K: std::borrow::Borrow<BK>,
66 {
67 im_rc::OrdMap::remove(self, k)
68 }
69
70 fn remove_with_key<BK: Ord>(&mut self, k: &BK) -> Option<(K, V)>
71 where
72 K: std::borrow::Borrow<BK>,
73 {
74 im_rc::OrdMap::remove_with_key(self, k)
75 }
76}
77
78impl<K: Ord + Clone, V: Clone> AsImOrdMap<K, V> for im::OrdMap<K, V> {
79 fn insert(&mut self, k: K, v: V) -> Option<V> {
80 im::OrdMap::insert(self, k, v)
81 }
82
83 fn remove<BK: Ord>(&mut self, k: &BK) -> Option<V>
84 where
85 K: std::borrow::Borrow<BK>,
86 {
87 im::OrdMap::remove(self, k)
88 }
89
90 fn remove_with_key<BK: Ord>(&mut self, k: &BK) -> Option<(K, V)>
91 where
92 K: std::borrow::Borrow<BK>,
93 {
94 im::OrdMap::remove_with_key(self, k)
95 }
96}