1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use crate::process::traversal::TraversalBuilder;
use crate::structure::{GValue, Pop};

pub struct SelectStep {
    params: Vec<GValue>,
}

impl SelectStep {
    fn new(params: Vec<GValue>) -> Self {
        SelectStep { params }
    }
}

impl SelectStep {
    pub fn take_params(self) -> Vec<GValue> {
        self.params
    }
}

pub trait IntoSelectStep {
    fn into_step(self) -> SelectStep;
}

impl IntoSelectStep for &str {
    fn into_step(self) -> SelectStep {
        SelectStep::new(vec![String::from(self).into()])
    }
}

impl IntoSelectStep for Pop {
    fn into_step(self) -> SelectStep {
        SelectStep::new(vec![GValue::Pop(self)])
    }
}

impl IntoSelectStep for Vec<&str> {
    fn into_step(self) -> SelectStep {
        SelectStep::new(self.into_iter().map(GValue::from).collect())
    }
}

impl IntoSelectStep for TraversalBuilder {
    fn into_step(self) -> SelectStep {
        SelectStep::new(vec![self.bytecode.into()])
    }
}

impl<B> IntoSelectStep for (Pop, B)
where
    B: Into<GValue>,
{
    fn into_step(self) -> SelectStep {
        SelectStep::new(vec![GValue::Pop(self.0), self.1.into()])
    }
}

macro_rules! impl_into_select {
    ($n:expr) => {
        impl<T: Clone> IntoSelectStep for [T; $n]
        where
            T: Into<String>,
        {
            fn into_step(self) -> SelectStep {
                SelectStep::new(self.iter().map(|e| e.clone().into().into()).collect())
            }
        }
    };
}

impl_into_select!(1);
impl_into_select!(2);
impl_into_select!(3);
impl_into_select!(4);
impl_into_select!(5);
impl_into_select!(6);
impl_into_select!(7);
impl_into_select!(8);
impl_into_select!(9);
impl_into_select!(10);