Skip to content

Commit 4104206

Browse files
committed
feat: impl Append for lots of tuples
1 parent c56728f commit 4104206

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

crates/chain/src/tx_data_traits.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,6 @@ pub trait Append {
9191
fn is_empty(&self) -> bool;
9292
}
9393

94-
impl Append for () {
95-
fn append(&mut self, _other: Self) {}
96-
97-
fn is_empty(&self) -> bool {
98-
true
99-
}
100-
}
101-
10294
impl<K: Ord, V> Append for BTreeMap<K, V> {
10395
fn append(&mut self, mut other: Self) {
10496
BTreeMap::append(self, &mut other)
@@ -129,13 +121,30 @@ impl<T> Append for Vec<T> {
129121
}
130122
}
131123

132-
impl<A: Append, B: Append> Append for (A, B) {
133-
fn append(&mut self, other: Self) {
134-
Append::append(&mut self.0, other.0);
135-
Append::append(&mut self.1, other.1);
136-
}
124+
macro_rules! impl_append_for_tuple {
125+
($($a:ident $b:tt)*) => {
126+
impl<$($a),*> Append for ($($a,)*) where $($a: Append),* {
137127

138-
fn is_empty(&self) -> bool {
139-
Append::is_empty(&self.0) && Append::is_empty(&self.1)
128+
fn append(&mut self, _other: Self) {
129+
$(Append::append(&mut self.$b, _other.$b) );*
130+
}
131+
132+
fn is_empty(&self) -> bool {
133+
$(Append::is_empty(&self.$b) && )* true
134+
}
135+
}
140136
}
141137
}
138+
139+
impl_append_for_tuple!();
140+
impl_append_for_tuple!(T0 0);
141+
impl_append_for_tuple!(T0 0 T1 1);
142+
impl_append_for_tuple!(T0 0 T1 1 T2 2);
143+
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3);
144+
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4);
145+
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5);
146+
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6);
147+
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7);
148+
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8);
149+
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9);
150+
impl_append_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

Comments
 (0)