solomon_gremlin/process/traversal/step/
select.rs

1use crate::process::traversal::TraversalBuilder;
2use crate::structure::{GValue, Pop};
3
4pub struct SelectStep {
5	params: Vec<GValue>,
6}
7
8impl SelectStep {
9	fn new(params: Vec<GValue>) -> Self {
10		SelectStep {
11			params,
12		}
13	}
14}
15
16impl From<SelectStep> for Vec<GValue> {
17	fn from(step: SelectStep) -> Self {
18		step.params
19	}
20}
21
22impl From<&str> for SelectStep {
23	fn from(param: &str) -> SelectStep {
24		SelectStep::new(vec![String::from(param).into()])
25	}
26}
27
28impl From<Pop> for SelectStep {
29	fn from(param: Pop) -> SelectStep {
30		SelectStep::new(vec![GValue::Pop(param)])
31	}
32}
33
34impl From<Vec<&str>> for SelectStep {
35	fn from(param: Vec<&str>) -> SelectStep {
36		SelectStep::new(param.into_iter().map(GValue::from).collect())
37	}
38}
39
40impl From<TraversalBuilder> for SelectStep {
41	fn from(param: TraversalBuilder) -> SelectStep {
42		SelectStep::new(vec![param.bytecode.into()])
43	}
44}
45
46impl<B> From<(Pop, B)> for SelectStep
47where
48	B: Into<GValue>,
49{
50	fn from(param: (Pop, B)) -> SelectStep {
51		SelectStep::new(vec![GValue::Pop(param.0), param.1.into()])
52	}
53}
54
55macro_rules! impl_into_select {
56	($n:expr) => {
57		impl<T: Clone> From<[T; $n]> for SelectStep
58		where
59			T: Into<String>,
60		{
61			fn from(param: [T; $n]) -> SelectStep {
62				SelectStep::new(param.iter().map(|e| e.clone().into().into()).collect())
63			}
64		}
65	};
66}
67
68impl_into_select!(1);
69impl_into_select!(2);
70impl_into_select!(3);
71impl_into_select!(4);
72impl_into_select!(5);
73impl_into_select!(6);
74impl_into_select!(7);
75impl_into_select!(8);
76impl_into_select!(9);
77impl_into_select!(10);