11use std:: fmt;
22
3- use crate :: format:: { Displayable , Formatter , Style , format_directives } ;
3+ use crate :: format:: { format_directives , Displayable , Formatter , Style } ;
44
55use crate :: query:: ast:: * ;
66
77
8- impl < ' a , T : Text < ' a > > Document < ' a , T >
8+ impl < ' a , T : Text < ' a > > Document < ' a , T >
99 where T : Text < ' a > ,
1010{
1111 /// Format a document according to style
@@ -23,7 +23,7 @@ fn to_string<T: Displayable>(v: &T) -> String {
2323 formatter. into_string ( )
2424}
2525
26- impl < ' a , T : Text < ' a > > Displayable for Document < ' a , T >
26+ impl < ' a , T : Text < ' a > > Displayable for Document < ' a , T >
2727 where T : Text < ' a > ,
2828{
2929 fn display ( & self , f : & mut Formatter ) {
@@ -33,7 +33,7 @@ impl<'a, T: Text<'a>> Displayable for Document<'a, T>
3333 }
3434}
3535
36- impl < ' a , T : Text < ' a > > Displayable for Definition < ' a , T >
36+ impl < ' a , T : Text < ' a > > Displayable for Definition < ' a , T >
3737 where T : Text < ' a > ,
3838{
3939 fn display ( & self , f : & mut Formatter ) {
@@ -44,7 +44,7 @@ impl<'a, T: Text<'a>> Displayable for Definition<'a, T>
4444 }
4545}
4646
47- impl < ' a , T : Text < ' a > > Displayable for OperationDefinition < ' a , T >
47+ impl < ' a , T : Text < ' a > > Displayable for OperationDefinition < ' a , T >
4848 where T : Text < ' a > ,
4949{
5050 fn display ( & self , f : & mut Formatter ) {
@@ -57,7 +57,7 @@ impl<'a, T: Text<'a>> Displayable for OperationDefinition<'a, T>
5757 }
5858}
5959
60- impl < ' a , T : Text < ' a > > Displayable for FragmentDefinition < ' a , T >
60+ impl < ' a , T : Text < ' a > > Displayable for FragmentDefinition < ' a , T >
6161 where T : Text < ' a > ,
6262{
6363 fn display ( & self , f : & mut Formatter ) {
@@ -77,7 +77,7 @@ impl<'a, T: Text<'a>> Displayable for FragmentDefinition<'a, T>
7777 }
7878}
7979
80- impl < ' a , T : Text < ' a > > Displayable for SelectionSet < ' a , T >
80+ impl < ' a , T : Text < ' a > > Displayable for SelectionSet < ' a , T >
8181 where T : Text < ' a > ,
8282{
8383 fn display ( & self , f : & mut Formatter ) {
@@ -91,7 +91,7 @@ impl<'a, T: Text<'a>> Displayable for SelectionSet<'a, T>
9191 }
9292}
9393
94- impl < ' a , T : Text < ' a > > Displayable for Selection < ' a , T >
94+ impl < ' a , T : Text < ' a > > Displayable for Selection < ' a , T >
9595 where T : Text < ' a > ,
9696{
9797 fn display ( & self , f : & mut Formatter ) {
@@ -103,25 +103,27 @@ impl<'a, T: Text<'a>> Displayable for Selection<'a, T>
103103 }
104104}
105105
106- fn format_arguments < ' a , T : Text < ' a > > ( arguments : & [ ( T :: Value , Value < ' a , T > ) ] , f : & mut Formatter )
106+ fn format_arguments < ' a , T : Text < ' a > > ( arguments : & [ ( T :: Value , Value < ' a , T > ) ] , f : & mut Formatter )
107107 where T : Text < ' a > ,
108108{
109109 if !arguments. is_empty ( ) {
110- f. write ( "(" ) ;
111- f. write ( arguments[ 0 ] . 0 . as_ref ( ) ) ;
110+ f. start_argument_block ( '(' ) ;
111+ f. start_argument ( ) ;
112+ f. write ( & arguments[ 0 ] . 0 . as_ref ( ) ) ;
112113 f. write ( ": " ) ;
113114 arguments[ 0 ] . 1 . display ( f) ;
114115 for arg in & arguments[ 1 ..] {
115- f. write ( ", " ) ;
116- f. write ( arg. 0 . as_ref ( ) ) ;
116+ f. deliniate_argument ( ) ;
117+ f. start_argument ( ) ;
118+ f. write ( & arg. 0 . as_ref ( ) ) ;
117119 f. write ( ": " ) ;
118120 arg. 1 . display ( f) ;
119121 }
120- f. write ( ")" ) ;
122+ f. end_argument_block ( ')' ) ;
121123 }
122124}
123125
124- impl < ' a , T : Text < ' a > > Displayable for Field < ' a , T >
126+ impl < ' a , T : Text < ' a > > Displayable for Field < ' a , T >
125127 where T : Text < ' a > ,
126128{
127129 fn display ( & self , f : & mut Formatter ) {
@@ -146,7 +148,7 @@ impl<'a, T: Text<'a>> Displayable for Field<'a, T>
146148 }
147149}
148150
149- impl < ' a , T : Text < ' a > > Displayable for Query < ' a , T >
151+ impl < ' a , T : Text < ' a > > Displayable for Query < ' a , T >
150152 where T : Text < ' a > ,
151153{
152154 fn display ( & self , f : & mut Formatter ) {
@@ -176,7 +178,7 @@ impl<'a, T: Text<'a>> Displayable for Query<'a, T>
176178 }
177179}
178180
179- impl < ' a , T : Text < ' a > > Displayable for Mutation < ' a , T >
181+ impl < ' a , T : Text < ' a > > Displayable for Mutation < ' a , T >
180182 where T : Text < ' a > ,
181183{
182184 fn display ( & self , f : & mut Formatter ) {
@@ -206,7 +208,7 @@ impl<'a, T: Text<'a>> Displayable for Mutation<'a, T>
206208 }
207209}
208210
209- impl < ' a , T : Text < ' a > > Displayable for Subscription < ' a , T >
211+ impl < ' a , T : Text < ' a > > Displayable for Subscription < ' a , T >
210212 where T : Text < ' a > ,
211213{
212214 fn display ( & self , f : & mut Formatter ) {
@@ -234,7 +236,7 @@ impl<'a, T: Text<'a>> Displayable for Subscription<'a, T>
234236 }
235237}
236238
237- impl < ' a , T : Text < ' a > > Displayable for VariableDefinition < ' a , T >
239+ impl < ' a , T : Text < ' a > > Displayable for VariableDefinition < ' a , T >
238240 where T : Text < ' a > ,
239241{
240242 fn display ( & self , f : & mut Formatter ) {
@@ -249,7 +251,7 @@ impl<'a, T: Text<'a>> Displayable for VariableDefinition<'a, T>
249251 }
250252}
251253
252- impl < ' a , T : Text < ' a > > Displayable for Type < ' a , T >
254+ impl < ' a , T : Text < ' a > > Displayable for Type < ' a , T >
253255 where T : Text < ' a > ,
254256{
255257 fn display ( & self , f : & mut Formatter ) {
@@ -268,12 +270,15 @@ impl<'a, T: Text<'a>> Displayable for Type<'a, T>
268270 }
269271}
270272
271- impl < ' a , T : Text < ' a > > Displayable for Value < ' a , T >
273+ impl < ' a , T : Text < ' a > > Displayable for Value < ' a , T >
272274 where T : Text < ' a > ,
273275{
274276 fn display ( & self , f : & mut Formatter ) {
275277 match * self {
276- Value :: Variable ( ref name) => { f. write ( "$" ) ; f. write ( name. as_ref ( ) ) ; } ,
278+ Value :: Variable ( ref name) => {
279+ f. write ( "$" ) ;
280+ f. write ( name. as_ref ( ) ) ;
281+ }
277282 Value :: Int ( ref num) => f. write ( & format ! ( "{}" , num. 0 ) ) ,
278283 Value :: Float ( val) => f. write ( & format ! ( "{}" , val) ) ,
279284 Value :: String ( ref val) => f. write_quoted ( val) ,
@@ -282,36 +287,39 @@ impl<'a, T: Text<'a>> Displayable for Value<'a, T>
282287 Value :: Null => f. write ( "null" ) ,
283288 Value :: Enum ( ref name) => f. write ( name. as_ref ( ) ) ,
284289 Value :: List ( ref items) => {
285- f. write ( "[" ) ;
290+ f. start_argument_block ( '[' ) ;
286291 if !items. is_empty ( ) {
292+ f. start_argument ( ) ;
287293 items[ 0 ] . display ( f) ;
288294 for item in & items[ 1 ..] {
289- f. write ( ", " ) ;
295+ f. deliniate_argument ( ) ;
296+ f. start_argument ( ) ;
290297 item. display ( f) ;
291298 }
292299 }
293- f. write ( "]" ) ;
300+ f. end_argument_block ( ']' ) ;
294301 }
295302 Value :: Object ( ref items) => {
296- f. write ( "{" ) ;
303+ f. start_argument_block ( '{' ) ;
297304 let mut first = true ;
298305 for ( name, value) in items. iter ( ) {
299306 if first {
300307 first = false ;
301308 } else {
302- f. write ( ", " ) ;
309+ f. deliniate_argument ( ) ;
303310 }
311+ f. start_argument ( ) ;
304312 f. write ( name. as_ref ( ) ) ;
305313 f. write ( ": " ) ;
306314 value. display ( f) ;
307315 }
308- f. write ( "}" ) ;
316+ f. end_argument_block ( '}' ) ;
309317 }
310318 }
311319 }
312320}
313321
314- impl < ' a , T : Text < ' a > > Displayable for InlineFragment < ' a , T >
322+ impl < ' a , T : Text < ' a > > Displayable for InlineFragment < ' a , T >
315323 where T : Text < ' a > ,
316324{
317325 fn display ( & self , f : & mut Formatter ) {
@@ -331,7 +339,7 @@ impl<'a, T: Text<'a>> Displayable for InlineFragment<'a, T>
331339 }
332340}
333341
334- impl < ' a , T : Text < ' a > > Displayable for TypeCondition < ' a , T >
342+ impl < ' a , T : Text < ' a > > Displayable for TypeCondition < ' a , T >
335343 where T : Text < ' a > ,
336344{
337345 fn display ( & self , f : & mut Formatter ) {
@@ -344,7 +352,7 @@ impl<'a, T: Text<'a>> Displayable for TypeCondition<'a, T>
344352 }
345353}
346354
347- impl < ' a , T : Text < ' a > > Displayable for FragmentSpread < ' a , T >
355+ impl < ' a , T : Text < ' a > > Displayable for FragmentSpread < ' a , T >
348356 where T : Text < ' a > ,
349357{
350358 fn display ( & self , f : & mut Formatter ) {
@@ -356,7 +364,7 @@ impl<'a, T: Text<'a>> Displayable for FragmentSpread<'a, T>
356364 }
357365}
358366
359- impl < ' a , T : Text < ' a > > Displayable for Directive < ' a , T >
367+ impl < ' a , T : Text < ' a > > Displayable for Directive < ' a , T >
360368 where T : Text < ' a > ,
361369{
362370 fn display ( & self , f : & mut Formatter ) {
@@ -366,9 +374,8 @@ impl<'a, T: Text<'a>> Displayable for Directive<'a, T>
366374 }
367375}
368376
369-
370377impl_display ! (
371- ' a
378+ ' a
372379 Document ,
373380 Definition ,
374381 OperationDefinition ,
0 commit comments