gremlin_client/structure/
label.rs1use crate::structure::T;
2
3pub enum LabelType {
4 Str(String),
5 Bool(bool),
6 T(T),
7}
8
9pub struct Labels(pub(crate) Vec<LabelType>);
10
11impl From<&str> for Labels {
12 fn from(param: &str) -> Labels {
13 Labels(vec![LabelType::Str(String::from(param))])
14 }
15}
16
17impl From<String> for Labels {
18 fn from(param: String) -> Labels {
19 Labels(vec![LabelType::Str(param)])
20 }
21}
22
23impl From<T> for Labels {
24 fn from(param: T) -> Labels {
25 Labels(vec![LabelType::T(param)])
26 }
27}
28
29impl From<()> for Labels {
30 fn from(_: ()) -> Labels {
31 Labels(vec![])
32 }
33}
34impl From<Vec<&str>> for Labels {
35 fn from(param: Vec<&str>) -> Labels {
36 Labels(
37 param
38 .into_iter()
39 .map(|val| LabelType::Str(String::from(val)))
40 .collect(),
41 )
42 }
43}
44impl From<Vec<String>> for Labels {
45 fn from(param: Vec<String>) -> Labels {
46 Labels(param.into_iter().map(LabelType::Str).collect())
47 }
48}
49
50impl From<bool> for Labels {
51 fn from(param: bool) -> Labels {
52 Labels(vec![LabelType::Bool(param)])
53 }
54}
55
56impl From<(bool, Vec<&str>)> for Labels {
57 fn from(param: (bool, Vec<&str>)) -> Labels {
58 let mut out: Vec<LabelType> = vec![LabelType::Bool(param.0)];
59 out.append(&mut Into::<Labels>::into(param.1).0.drain(..).collect());
60 Labels(out)
61 }
62}
63
64impl From<(bool, T, Vec<&str>)> for Labels {
65 fn from(param: (bool, T, Vec<&str>)) -> Labels {
66 let mut out: Vec<LabelType> = vec![LabelType::Bool(param.0)];
67 out.append(&mut Into::<Labels>::into(param.1).0.drain(..).collect());
68 out.append(&mut Into::<Labels>::into(param.2).0.drain(..).collect());
69 Labels(out)
70 }
71}
72
73impl From<(T, Vec<&str>)> for Labels {
74 fn from(param: (T, Vec<&str>)) -> Labels {
75 let mut out: Vec<LabelType> = vec![LabelType::T(param.0)];
76 out.append(&mut Into::<Labels>::into(param.1).0.drain(..).collect());
77 Labels(out)
78 }
79}
80
81macro_rules! impl_into_labels_str {
82 ($n:expr) => {
83 impl From<[&str; $n]> for Labels {
84 fn from(param: [&str; $n]) -> Labels {
85 Labels(
86 param
87 .iter()
88 .map(|s| LabelType::Str(String::from(*s)))
89 .collect(),
90 )
91 }
92 }
93 };
94}
95
96impl_into_labels_str!(1);
97impl_into_labels_str!(2);
98impl_into_labels_str!(3);
99impl_into_labels_str!(4);
100impl_into_labels_str!(5);
101impl_into_labels_str!(6);
102impl_into_labels_str!(7);
103impl_into_labels_str!(8);
104impl_into_labels_str!(9);
105impl_into_labels_str!(10);
106
107macro_rules! impl_into_labels_string {
108 ($n:expr) => {
109 impl From<[String; $n]> for Labels {
110 fn from(param: [String; $n]) -> Labels {
111 Labels(
112 param
113 .iter()
114 .map(|val| LabelType::Str(val.clone()))
115 .collect(),
116 )
117 }
118 }
119 };
120}
121
122impl_into_labels_string!(1);
123impl_into_labels_string!(2);
124impl_into_labels_string!(3);
125impl_into_labels_string!(4);
126impl_into_labels_string!(5);
127impl_into_labels_string!(6);
128impl_into_labels_string!(7);
129impl_into_labels_string!(8);
130impl_into_labels_string!(9);
131impl_into_labels_string!(10);