graphql_toolkit_ast/
lib.rs1pub use graphql_toolkit_value::*;
6pub use pos::*;
7pub use types::*;
8
9mod pos;
10mod types;
11
12pub trait IntoAst<T> {
14 #[must_use]
16 fn into_ast(self) -> T;
17}
18
19macro_rules! impl_into_ast {
20 ($($ty:ty),* $(,)?) => {
21 $(
22 impl IntoAst<$ty> for $ty {
23 #[inline(always)]
25 fn into_ast(self) -> $ty {
26 self
27 }
28 }
29 )*
30 };
31}
32
33impl<S> IntoAst<Name> for S
34where
35 S: AsRef<str>,
36{
37 #[inline]
38 fn into_ast(self) -> Name {
39 Name::new(self)
40 }
41}
42
43impl_into_ast! {
45 BaseType, ConstValue, Directive, DocumentOperations, Field, FragmentDefinition, FragmentSpread,
46 InlineFragment, Number, OperationDefinition, OperationType, Selection, SelectionSet,
47 Type, TypeCondition, Value, VariableDefinition,
48}
49
50pub trait AstPositionExt: Sized {
52 #[must_use]
54 #[inline]
55 fn default_position(self) -> Positioned<Self> {
56 Positioned::new(self, Default::default())
57 }
58
59 #[must_use]
61 #[inline]
62 fn with_position(self, pos: Pos) -> Positioned<Self> {
63 Positioned::new(self, pos)
64 }
65}
66
67macro_rules! impl_ast_position_ext {
68 ($($ty:ty),* $(,)?) => {
69 $(
70 impl AstPositionExt for $ty {}
71 )*
72 };
73}
74
75impl_ast_position_ext! {
77 BaseType, ConstValue, Directive, DocumentOperations, Field, FragmentDefinition, FragmentSpread,
78 InlineFragment, Name, Number, OperationDefinition, OperationType, Selection, SelectionSet,
79 Type, TypeCondition, Value, VariableDefinition,
80}