feat: impl Append for lots of tuples
This commit is contained in:
parent
c56728ff13
commit
4104206980
@ -91,14 +91,6 @@ pub trait Append {
|
|||||||
fn is_empty(&self) -> bool;
|
fn is_empty(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Append for () {
|
|
||||||
fn append(&mut self, _other: Self) {}
|
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<K: Ord, V> Append for BTreeMap<K, V> {
|
impl<K: Ord, V> Append for BTreeMap<K, V> {
|
||||||
fn append(&mut self, mut other: Self) {
|
fn append(&mut self, mut other: Self) {
|
||||||
BTreeMap::append(self, &mut other)
|
BTreeMap::append(self, &mut other)
|
||||||
@ -129,13 +121,30 @@ impl<T> Append for Vec<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Append, B: Append> Append for (A, B) {
|
macro_rules! impl_append_for_tuple {
|
||||||
fn append(&mut self, other: Self) {
|
($($a:ident $b:tt)*) => {
|
||||||
Append::append(&mut self.0, other.0);
|
impl<$($a),*> Append for ($($a,)*) where $($a: Append),* {
|
||||||
Append::append(&mut self.1, other.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
fn append(&mut self, _other: Self) {
|
||||||
Append::is_empty(&self.0) && Append::is_empty(&self.1)
|
$(Append::append(&mut self.$b, _other.$b) );*
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_empty(&self) -> bool {
|
||||||
|
$(Append::is_empty(&self.$b) && )* true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_append_for_tuple!();
|
||||||
|
impl_append_for_tuple!(T0 0);
|
||||||
|
impl_append_for_tuple!(T0 0 T1 1);
|
||||||
|
impl_append_for_tuple!(T0 0 T1 1 T2 2);
|
||||||
|
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3);
|
||||||
|
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4);
|
||||||
|
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5);
|
||||||
|
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6);
|
||||||
|
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7);
|
||||||
|
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8);
|
||||||
|
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9);
|
||||||
|
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user