|
1 | | -use crate::collections::{BTreeMap, BTreeSet}; |
2 | 1 | use crate::{BlockId, ConfirmationBlockTime}; |
3 | | -use alloc::vec::Vec; |
4 | 2 |
|
5 | 3 | /// Trait that "anchors" blockchain data to a specific block of height and hash. |
6 | 4 | /// |
@@ -121,83 +119,3 @@ impl AnchorFromBlockPosition for ConfirmationBlockTime { |
121 | 119 | } |
122 | 120 | } |
123 | 121 | } |
124 | | - |
125 | | -/// Trait that makes an object mergeable. |
126 | | -pub trait Merge: Default { |
127 | | - /// Merge another object of the same type onto `self`. |
128 | | - fn merge(&mut self, other: Self); |
129 | | - |
130 | | - /// Returns whether the structure is considered empty. |
131 | | - fn is_empty(&self) -> bool; |
132 | | - |
133 | | - /// Take the value, replacing it with the default value. |
134 | | - fn take(&mut self) -> Option<Self> { |
135 | | - if self.is_empty() { |
136 | | - None |
137 | | - } else { |
138 | | - Some(core::mem::take(self)) |
139 | | - } |
140 | | - } |
141 | | -} |
142 | | - |
143 | | -impl<K: Ord, V> Merge for BTreeMap<K, V> { |
144 | | - fn merge(&mut self, other: Self) { |
145 | | - // We use `extend` instead of `BTreeMap::append` due to performance issues with `append`. |
146 | | - // Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420 |
147 | | - BTreeMap::extend(self, other) |
148 | | - } |
149 | | - |
150 | | - fn is_empty(&self) -> bool { |
151 | | - BTreeMap::is_empty(self) |
152 | | - } |
153 | | -} |
154 | | - |
155 | | -impl<T: Ord> Merge for BTreeSet<T> { |
156 | | - fn merge(&mut self, other: Self) { |
157 | | - // We use `extend` instead of `BTreeMap::append` due to performance issues with `append`. |
158 | | - // Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420 |
159 | | - BTreeSet::extend(self, other) |
160 | | - } |
161 | | - |
162 | | - fn is_empty(&self) -> bool { |
163 | | - BTreeSet::is_empty(self) |
164 | | - } |
165 | | -} |
166 | | - |
167 | | -impl<T> Merge for Vec<T> { |
168 | | - fn merge(&mut self, mut other: Self) { |
169 | | - Vec::append(self, &mut other) |
170 | | - } |
171 | | - |
172 | | - fn is_empty(&self) -> bool { |
173 | | - Vec::is_empty(self) |
174 | | - } |
175 | | -} |
176 | | - |
177 | | -macro_rules! impl_merge_for_tuple { |
178 | | - ($($a:ident $b:tt)*) => { |
179 | | - impl<$($a),*> Merge for ($($a,)*) where $($a: Merge),* { |
180 | | - |
181 | | - fn merge(&mut self, _other: Self) { |
182 | | - $(Merge::merge(&mut self.$b, _other.$b) );* |
183 | | - } |
184 | | - |
185 | | - fn is_empty(&self) -> bool { |
186 | | - $(Merge::is_empty(&self.$b) && )* true |
187 | | - } |
188 | | - } |
189 | | - } |
190 | | -} |
191 | | - |
192 | | -impl_merge_for_tuple!(); |
193 | | -impl_merge_for_tuple!(T0 0); |
194 | | -impl_merge_for_tuple!(T0 0 T1 1); |
195 | | -impl_merge_for_tuple!(T0 0 T1 1 T2 2); |
196 | | -impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3); |
197 | | -impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4); |
198 | | -impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5); |
199 | | -impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6); |
200 | | -impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7); |
201 | | -impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8); |
202 | | -impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9); |
203 | | -impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 T10 10); |
0 commit comments