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
use crate::process::traversal::TraversalBuilder;
use crate::structure::GValue;

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

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

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

pub trait IntoMatchStep {
    fn into_step(self) -> MatchStep;
}

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

impl IntoMatchStep for Vec<TraversalBuilder> {
    fn into_step(self) -> MatchStep {
        MatchStep::new(self.into_iter().map(|s| s.bytecode.into()).collect())
    }
}

macro_rules! impl_into_match {
    ($n:expr) => {
        impl IntoMatchStep for [TraversalBuilder; $n] {
            fn into_step(self) -> MatchStep {
                MatchStep::new(
                    self.into_iter()
                        .map(|s| s.bytecode.clone().into())
                        .collect(),
                )
            }
        }
    };
}

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