@@ -6,26 +6,27 @@ use crate::{
66 executor:: Variables ,
77 parser:: Spanning ,
88 value:: { DefaultScalarValue , ScalarValue } ,
9+ ArcStr ,
910} ;
1011
1112/// A type literal in the syntax tree
1213///
1314/// This enum carries no semantic information and might refer to types that do
1415/// not exist.
1516#[ derive( Clone , Eq , PartialEq , Debug ) ]
16- pub enum Type < ' a > {
17+ pub enum Type < N = ArcStr > {
1718 /// A nullable named type, e.g. `String`
18- Named ( Cow < ' a , str > ) ,
19+ Named ( N ) ,
1920 /// A nullable list type, e.g. `[String]`
2021 ///
2122 /// 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 > ) ,
2324 /// A non-null named type, e.g. `String!`
24- NonNullNamed ( Cow < ' a , str > ) ,
25+ NonNullNamed ( N ) ,
2526 /// A non-null list type, e.g. `[String]!`.
2627 ///
2728 /// 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 > ) ,
2930}
3031
3132/// A JSON-like value that can be passed into the query execution, either
@@ -47,7 +48,7 @@ pub enum InputValue<S = DefaultScalarValue> {
4748
4849#[ derive( Clone , PartialEq , Debug ) ]
4950pub struct VariableDefinition < ' a , S > {
50- pub var_type : Spanning < Type < ' a > > ,
51+ pub var_type : Spanning < Type < & ' a str > > ,
5152 pub default_value : Option < Spanning < InputValue < S > > > ,
5253 pub directives : Option < Vec < Spanning < Directive < ' a , S > > > > ,
5354}
@@ -194,13 +195,13 @@ pub trait ToInputValue<S = DefaultScalarValue>: Sized {
194195 fn to_input_value ( & self ) -> InputValue < S > ;
195196}
196197
197- impl < ' a > Type < ' a > {
198+ impl < N : AsRef < str > > Type < N > {
198199 /// Get the name of a named type.
199200 ///
200201 /// Only applies to named types; lists will return `None`.
201202 pub fn name ( & self ) -> Option < & str > {
202203 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 ( ) ) ,
204205 _ => None ,
205206 }
206207 }
@@ -210,7 +211,7 @@ impl<'a> Type<'a> {
210211 /// All type literals contain exactly one named type.
211212 pub fn innermost_name ( & self ) -> & str {
212213 match * self {
213- Type :: Named ( ref n) | Type :: NonNullNamed ( ref n) => n,
214+ Type :: Named ( ref n) | Type :: NonNullNamed ( ref n) => n. as_ref ( ) ,
214215 Type :: List ( ref l, _) | Type :: NonNullList ( ref l, _) => l. innermost_name ( ) ,
215216 }
216217 }
@@ -221,7 +222,7 @@ impl<'a> Type<'a> {
221222 }
222223}
223224
224- impl < ' a > fmt:: Display for Type < ' a > {
225+ impl < N : fmt :: Display > fmt:: Display for Type < N > {
225226 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
226227 match self {
227228 Self :: Named ( n) => write ! ( f, "{n}" ) ,
0 commit comments