solomon_gremlin/process/traversal/step/
has.rs1use crate::structure::GValue;
2use crate::structure::{Either2, TextP, T};
3use crate::structure::{IntoPredicate, Predicate};
4
5pub enum HasStepKey {
6 Str(String),
7 T(T),
8}
9
10impl Into<HasStepKey> for T {
11 fn into(self) -> HasStepKey {
12 HasStepKey::T(self)
13 }
14}
15
16impl Into<HasStepKey> for String {
17 fn into(self) -> HasStepKey {
18 HasStepKey::Str(self)
19 }
20}
21
22impl Into<HasStepKey> for &str {
23 fn into(self) -> HasStepKey {
24 HasStepKey::Str(String::from(self))
25 }
26}
27
28pub struct HasStep {
29 label: Option<String>,
30 key: HasStepKey,
31 predicate: Option<Either2<Predicate, TextP>>,
32}
33
34impl From<HasStep> for Vec<GValue> {
35 fn from(step: HasStep) -> Self {
36 let mut params: Vec<GValue> = vec![];
37
38 if let Some(s) = step.label {
39 params.push(Into::into(s));
40 }
41
42 match step.key {
43 HasStepKey::Str(key) => params.push(Into::into(key)),
44 HasStepKey::T(key) => params.push(Into::into(key)),
45 };
46
47 if let Some(p) = step.predicate {
48 params.push(Into::into(p));
49 }
50
51 params
52 }
53}
54
55impl<A, B> From<(A, B)> for HasStep
56where
57 A: Into<HasStepKey>,
58 B: IntoPredicate,
59{
60 fn from(param: (A, B)) -> Self {
61 HasStep {
62 label: None,
63 key: param.0.into(),
64 predicate: Some(param.1.into_predicate()),
65 }
66 }
67}
68
69impl<A, B, C> From<(A, B, C)> for HasStep
70where
71 A: Into<String>,
72 B: Into<HasStepKey>,
73 C: IntoPredicate,
74{
75 fn from(param: (A, B, C)) -> Self {
76 HasStep {
77 label: Some(param.0.into()),
78 key: param.1.into(),
79 predicate: Some(param.2.into_predicate()),
80 }
81 }
82}
83
84impl From<String> for HasStep {
85 fn from(param: String) -> Self {
86 HasStep {
87 label: None,
88 key: HasStepKey::Str(param),
89 predicate: None,
90 }
91 }
92}
93
94impl From<&str> for HasStep {
95 fn from(param: &str) -> Self {
96 HasStep {
97 label: None,
98 key: HasStepKey::Str(String::from(param)),
99 predicate: None,
100 }
101 }
102}