Browse Source

Add and use for_each_tuple!

master
Adrian Heine 5 years ago
parent
commit
5d5e9dfcb4
  1. 15
      src/for_each_tuple.rs
  2. 3
      src/lib.rs
  3. 78
      src/symbols/list.rs

15
src/for_each_tuple.rs

@ -0,0 +1,15 @@
macro_rules! for_each_tuple_ {
( $m:ident !! ) => (
$m! { }
);
( $m:ident !! $h:ident, $($t:ident,)* ) => (
$m! { $h $($t)* }
for_each_tuple_! { $m !! $($t,)* }
);
}
#[macro_export]
macro_rules! for_each_tuple {
( $m:ident ) => (
for_each_tuple_! { $m !! A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, }
);
}

3
src/lib.rs

@ -21,6 +21,9 @@ missing_debug_implementations
extern crate regex; extern crate regex;
extern crate users; extern crate users;
#[macro_use]
mod for_each_tuple;
pub mod bin; pub mod bin;
pub mod build; pub mod build;
pub mod command_runner; pub mod command_runner;

78
src/symbols/list.rs

@ -75,80 +75,18 @@ impl<'a> Symbol for List<'a> {
} }
} }
impl<'a, A: 'a + Symbol, B: 'a + Symbol> From<(A, B)> for List<'a> {
fn from((a, b): (A, B)) -> Self {
Self::new(vec![Box::new(a), Box::new(b)])
macro_rules! from_tuple {
( $($name:ident)* ) => (
#[allow(non_snake_case)]
impl<'a, $($name: 'a + Symbol,)*> From<($($name,)*)> for List<'a> {
fn from(($($name,)*): ($($name,)*)) -> Self {
Self::new(vec![$(Box::new($name),)*])
} }
}
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol> From<(A, B, C)> for List<'a> {
fn from((a, b, c): (A, B, C)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c)])
}
}
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol> From<(A, B, C, D)> for List<'a> {
fn from((a, b, c, d): (A, B, C, D)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d)])
}
}
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol> From<(A, B, C, D, E)> for List<'a> {
fn from((a, b, c, d, e): (A, B, C, D, E)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e)])
}
}
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol> From<(A, B, C, D, E, F)> for List<'a> {
fn from((a, b, c, d, e, f): (A, B, C, D, E, F)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f)])
}
}
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol> From<(A, B, C, D, E, F, G)> for List<'a> {
fn from((a, b, c, d, e, f, g): (A, B, C, D, E, F, G)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g)])
} }
);
} }
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol> From<(A, B, C, D, E, F, G, H)> for List<'a> {
fn from((a, b, c, d, e, f, g, h): (A, B, C, D, E, F, G, H)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h)])
}
}
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K)> for List<'a> {
fn from((a, b, c, d, e, f, g, h, i, j, k): (A, B, C, D, E, F, G, H, I, J, K)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h), Box::new(i), Box::new(j), Box::new(k)])
}
}
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L)> for List<'a> {
fn from((a, b, c, d, e, f, g, h, i, j, k, l): (A, B, C, D, E, F, G, H, I, J, K, L)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h), Box::new(i), Box::new(j), Box::new(k), Box::new(l)])
}
}
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol, M: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L, M)> for List<'a> {
fn from((a, b, c, d, e, f, g, h, i, j, k, l, m): (A, B, C, D, E, F, G, H, I, J, K, L, M)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h), Box::new(i), Box::new(j), Box::new(k), Box::new(l), Box::new(m)])
}
}
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol, M: 'a + Symbol, N: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L, M, N)> for List<'a> {
fn from((a, b, c, d, e, f, g, h, i, j, k, l, m, n): (A, B, C, D, E, F, G, H, I, J, K, L, M, N)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h), Box::new(i), Box::new(j), Box::new(k), Box::new(l), Box::new(m), Box::new(n)])
}
}
for_each_tuple!(from_tuple);
struct SymbolListAction<'a> { struct SymbolListAction<'a> {
runner: &'a dyn SymbolRunner, runner: &'a dyn SymbolRunner,

Loading…
Cancel
Save