@@ -6,26 +6,27 @@ use crate::{
6
6
executor:: Variables ,
7
7
parser:: Spanning ,
8
8
value:: { DefaultScalarValue , ScalarValue } ,
9
+ ArcStr ,
9
10
} ;
10
11
11
12
/// A type literal in the syntax tree
12
13
///
13
14
/// This enum carries no semantic information and might refer to types that do
14
15
/// not exist.
15
16
#[ derive( Clone , Eq , PartialEq , Debug ) ]
16
- pub enum Type < ' a > {
17
+ pub enum Type < N = ArcStr > {
17
18
/// A nullable named type, e.g. `String`
18
- Named ( Cow < ' a , str > ) ,
19
+ Named ( N ) ,
19
20
/// A nullable list type, e.g. `[String]`
20
21
///
21
22
/// The list itself is what's nullable, the containing type might be non-null.
22
- List ( Box < Type < ' a > > , Option < usize > ) ,
23
+ List ( Box < Type < N > > , Option < usize > ) ,
23
24
/// A non-null named type, e.g. `String!`
24
- NonNullNamed ( Cow < ' a , str > ) ,
25
+ NonNullNamed ( N ) ,
25
26
/// A non-null list type, e.g. `[String]!`.
26
27
///
27
28
/// The list itself is what's non-null, the containing type might be null.
28
- NonNullList ( Box < Type < ' a > > , Option < usize > ) ,
29
+ NonNullList ( Box < Type < N > > , Option < usize > ) ,
29
30
}
30
31
31
32
/// A JSON-like value that can be passed into the query execution, either
@@ -47,7 +48,7 @@ pub enum InputValue<S = DefaultScalarValue> {
47
48
48
49
#[ derive( Clone , PartialEq , Debug ) ]
49
50
pub struct VariableDefinition < ' a , S > {
50
- pub var_type : Spanning < Type < ' a > > ,
51
+ pub var_type : Spanning < Type < & ' a str > > ,
51
52
pub default_value : Option < Spanning < InputValue < S > > > ,
52
53
pub directives : Option < Vec < Spanning < Directive < ' a , S > > > > ,
53
54
}
@@ -194,13 +195,13 @@ pub trait ToInputValue<S = DefaultScalarValue>: Sized {
194
195
fn to_input_value ( & self ) -> InputValue < S > ;
195
196
}
196
197
197
- impl < ' a > Type < ' a > {
198
+ impl < N : AsRef < str > > Type < N > {
198
199
/// Get the name of a named type.
199
200
///
200
201
/// Only applies to named types; lists will return `None`.
201
202
pub fn name ( & self ) -> Option < & str > {
202
203
match * self {
203
- Type :: Named ( ref n) | Type :: NonNullNamed ( ref n) => Some ( n) ,
204
+ Type :: Named ( ref n) | Type :: NonNullNamed ( ref n) => Some ( n. as_ref ( ) ) ,
204
205
_ => None ,
205
206
}
206
207
}
@@ -210,7 +211,7 @@ impl<'a> Type<'a> {
210
211
/// All type literals contain exactly one named type.
211
212
pub fn innermost_name ( & self ) -> & str {
212
213
match * self {
213
- Type :: Named ( ref n) | Type :: NonNullNamed ( ref n) => n,
214
+ Type :: Named ( ref n) | Type :: NonNullNamed ( ref n) => n. as_ref ( ) ,
214
215
Type :: List ( ref l, _) | Type :: NonNullList ( ref l, _) => l. innermost_name ( ) ,
215
216
}
216
217
}
@@ -221,7 +222,7 @@ impl<'a> Type<'a> {
221
222
}
222
223
}
223
224
224
- impl < ' a > fmt:: Display for Type < ' a > {
225
+ impl < N : fmt :: Display > fmt:: Display for Type < N > {
225
226
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
226
227
match self {
227
228
Self :: Named ( n) => write ! ( f, "{n}" ) ,
0 commit comments