graphql_query/ast/
ast_conversion.rs

1// #![allow(clippy::needless_update)]
2use bumpalo::collections::{vec::IntoIter, Vec};
3use super::ast::*;
4
5// TODO: from_iter_in could be a good helper here as well
6
7impl<'a> IntoIterator for ListValue<'a> {
8    type Item = Value<'a>;
9    type IntoIter = IntoIter<'a, Value<'a>>;
10    #[inline]
11    fn into_iter(self) -> Self::IntoIter {
12        self.children.into_iter()
13    }
14}
15
16impl<'a> IntoIterator for ObjectValue<'a> {
17    type Item = ObjectField<'a>;
18    type IntoIter = IntoIter<'a, ObjectField<'a>>;
19    #[inline]
20    fn into_iter(self) -> Self::IntoIter {
21        self.children.into_iter()
22    }
23}
24
25impl<'a> IntoIterator for Arguments<'a> {
26    type Item = Argument<'a>;
27    type IntoIter = IntoIter<'a, Argument<'a>>;
28    #[inline]
29    fn into_iter(self) -> Self::IntoIter {
30        self.children.into_iter()
31    }
32}
33
34impl<'a> IntoIterator for Directives<'a> {
35    type Item = Directive<'a>;
36    type IntoIter = IntoIter<'a, Directive<'a>>;
37    #[inline]
38    fn into_iter(self) -> Self::IntoIter {
39        self.children.into_iter()
40    }
41}
42
43impl<'a> IntoIterator for VariableDefinitions<'a> {
44    type Item = VariableDefinition<'a>;
45    type IntoIter = IntoIter<'a, VariableDefinition<'a>>;
46    #[inline]
47    fn into_iter(self) -> Self::IntoIter {
48        self.children.into_iter()
49    }
50}
51
52impl<'a> IntoIterator for SelectionSet<'a> {
53    type Item = Selection<'a>;
54    type IntoIter = IntoIter<'a, Selection<'a>>;
55    #[inline]
56    fn into_iter(self) -> Self::IntoIter {
57        self.selections.into_iter()
58    }
59}
60
61pub trait DefaultIn<'a> {
62    fn default_in(arena: &'a bumpalo::Bump) -> Self;
63}
64
65impl<'a> DefaultIn<'a> for Document<'a> {
66    fn default_in(arena: &'a bumpalo::Bump) -> Self {
67        Document {
68            definitions: Vec::new_in(&arena),
69            size_hint: 0
70        }
71    }
72}
73
74impl<'a> DefaultIn<'a> for VariableDefinitions<'a> {
75    fn default_in(arena: &'a bumpalo::Bump) -> Self {
76        VariableDefinitions {
77            children: Vec::new_in(&arena),
78        }
79    }
80}
81
82impl<'a> DefaultIn<'a> for ObjectValue<'a> {
83    fn default_in(arena: &'a bumpalo::Bump) -> Self {
84        ObjectValue {
85            children: Vec::new_in(&arena),
86        }
87    }
88}
89
90impl<'a> DefaultIn<'a> for ListValue<'a> {
91    fn default_in(arena: &'a bumpalo::Bump) -> Self {
92        ListValue {
93            children: Vec::new_in(&arena),
94        }
95    }
96}
97
98impl<'a> DefaultIn<'a> for Arguments<'a> {
99    fn default_in(arena: &'a bumpalo::Bump) -> Self {
100        Arguments {
101            children: Vec::new_in(&arena),
102        }
103    }
104}
105
106impl<'a> DefaultIn<'a> for Directives<'a> {
107    fn default_in(arena: &'a bumpalo::Bump) -> Self {
108        Directives {
109            children: Vec::new_in(&arena),
110        }
111    }
112}
113
114impl<'a> DefaultIn<'a> for SelectionSet<'a> {
115    fn default_in(arena: &'a bumpalo::Bump) -> Self {
116        SelectionSet {
117            selections: Vec::new_in(&arena),
118        }
119    }
120}
121
122impl<'a> From<&'a str> for NamedType<'a> {
123    #[inline]
124    fn from(name: &'a str) -> Self {
125        NamedType { name }
126    }
127}
128
129impl<'a> From<&'a str> for Variable<'a> {
130    #[inline]
131    fn from(name: &'a str) -> Variable<'a> {
132        Variable { name }
133    }
134}
135
136impl From<bool> for BooleanValue {
137    #[inline]
138    fn from(value: bool) -> Self {
139        BooleanValue { value }
140    }
141}
142
143impl<'a> From<&'a str> for StringValue<'a> {
144    #[inline]
145    fn from(value: &'a str) -> Self {
146        StringValue { value }
147    }
148}
149
150impl<'a> From<Variable<'a>> for Value<'a> {
151    #[inline]
152    fn from(x: Variable<'a>) -> Self {
153        Value::Variable(x)
154    }
155}
156
157impl<'a> From<StringValue<'a>> for Value<'a> {
158    #[inline]
159    fn from(x: StringValue<'a>) -> Self {
160        Value::String(x)
161    }
162}
163
164impl<'a> From<FloatValue<'a>> for Value<'a> {
165    #[inline]
166    fn from(x: FloatValue<'a>) -> Self {
167        Value::Float(x)
168    }
169}
170
171impl<'a> From<IntValue<'a>> for Value<'a> {
172    #[inline]
173    fn from(x: IntValue<'a>) -> Self {
174        Value::Int(x)
175    }
176}
177
178impl<'a> From<BooleanValue> for Value<'a> {
179    #[inline]
180    fn from(x: BooleanValue) -> Self {
181        Value::Boolean(x)
182    }
183}
184
185impl<'a> From<EnumValue<'a>> for Value<'a> {
186    #[inline]
187    fn from(x: EnumValue<'a>) -> Self {
188        Value::Enum(x)
189    }
190}
191
192impl<'a> From<ListValue<'a>> for Value<'a> {
193    #[inline]
194    fn from(x: ListValue<'a>) -> Self {
195        Value::List(x)
196    }
197}
198
199impl<'a> From<ObjectValue<'a>> for Value<'a> {
200    #[inline]
201    fn from(x: ObjectValue<'a>) -> Self {
202        Value::Object(x)
203    }
204}
205
206impl<'a> From<NamedType<'a>> for Type<'a> {
207    #[inline]
208    fn from(x: NamedType<'a>) -> Self {
209        Type::NamedType(x)
210    }
211}
212
213impl<'a> From<Field<'a>> for Selection<'a> {
214    #[inline]
215    fn from(x: Field<'a>) -> Self {
216        Selection::Field(x)
217    }
218}
219
220impl<'a> From<FragmentSpread<'a>> for Selection<'a> {
221    #[inline]
222    fn from(x: FragmentSpread<'a>) -> Self {
223        Selection::FragmentSpread(x)
224    }
225}
226
227impl<'a> From<InlineFragment<'a>> for Selection<'a> {
228    #[inline]
229    fn from(x: InlineFragment<'a>) -> Self {
230        Selection::InlineFragment(x)
231    }
232}
233
234impl<'a> From<OperationDefinition<'a>> for Definition<'a> {
235    #[inline]
236    fn from(x: OperationDefinition<'a>) -> Self {
237        Definition::Operation(x)
238    }
239}
240
241impl<'a> From<FragmentDefinition<'a>> for Definition<'a> {
242    #[inline]
243    fn from(x: FragmentDefinition<'a>) -> Self {
244        Definition::Fragment(x)
245    }
246}