1
1
use std:: fmt;
2
2
3
- use crate :: format:: { Displayable , Formatter , Style , format_directives } ;
3
+ use crate :: format:: { format_directives , Displayable , Formatter , Style } ;
4
4
5
5
use crate :: query:: ast:: * ;
6
6
7
7
8
- impl < ' a , T : Text < ' a > > Document < ' a , T >
8
+ impl < ' a , T : Text < ' a > > Document < ' a , T >
9
9
where T : Text < ' a > ,
10
10
{
11
11
/// Format a document according to style
@@ -23,7 +23,7 @@ fn to_string<T: Displayable>(v: &T) -> String {
23
23
formatter. into_string ( )
24
24
}
25
25
26
- impl < ' a , T : Text < ' a > > Displayable for Document < ' a , T >
26
+ impl < ' a , T : Text < ' a > > Displayable for Document < ' a , T >
27
27
where T : Text < ' a > ,
28
28
{
29
29
fn display ( & self , f : & mut Formatter ) {
@@ -33,7 +33,7 @@ impl<'a, T: Text<'a>> Displayable for Document<'a, T>
33
33
}
34
34
}
35
35
36
- impl < ' a , T : Text < ' a > > Displayable for Definition < ' a , T >
36
+ impl < ' a , T : Text < ' a > > Displayable for Definition < ' a , T >
37
37
where T : Text < ' a > ,
38
38
{
39
39
fn display ( & self , f : & mut Formatter ) {
@@ -44,7 +44,7 @@ impl<'a, T: Text<'a>> Displayable for Definition<'a, T>
44
44
}
45
45
}
46
46
47
- impl < ' a , T : Text < ' a > > Displayable for OperationDefinition < ' a , T >
47
+ impl < ' a , T : Text < ' a > > Displayable for OperationDefinition < ' a , T >
48
48
where T : Text < ' a > ,
49
49
{
50
50
fn display ( & self , f : & mut Formatter ) {
@@ -57,7 +57,7 @@ impl<'a, T: Text<'a>> Displayable for OperationDefinition<'a, T>
57
57
}
58
58
}
59
59
60
- impl < ' a , T : Text < ' a > > Displayable for FragmentDefinition < ' a , T >
60
+ impl < ' a , T : Text < ' a > > Displayable for FragmentDefinition < ' a , T >
61
61
where T : Text < ' a > ,
62
62
{
63
63
fn display ( & self , f : & mut Formatter ) {
@@ -77,7 +77,7 @@ impl<'a, T: Text<'a>> Displayable for FragmentDefinition<'a, T>
77
77
}
78
78
}
79
79
80
- impl < ' a , T : Text < ' a > > Displayable for SelectionSet < ' a , T >
80
+ impl < ' a , T : Text < ' a > > Displayable for SelectionSet < ' a , T >
81
81
where T : Text < ' a > ,
82
82
{
83
83
fn display ( & self , f : & mut Formatter ) {
@@ -91,7 +91,7 @@ impl<'a, T: Text<'a>> Displayable for SelectionSet<'a, T>
91
91
}
92
92
}
93
93
94
- impl < ' a , T : Text < ' a > > Displayable for Selection < ' a , T >
94
+ impl < ' a , T : Text < ' a > > Displayable for Selection < ' a , T >
95
95
where T : Text < ' a > ,
96
96
{
97
97
fn display ( & self , f : & mut Formatter ) {
@@ -103,25 +103,27 @@ impl<'a, T: Text<'a>> Displayable for Selection<'a, T>
103
103
}
104
104
}
105
105
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 )
107
107
where T : Text < ' a > ,
108
108
{
109
109
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 ( ) ) ;
112
113
f. write ( ": " ) ;
113
114
arguments[ 0 ] . 1 . display ( f) ;
114
115
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 ( ) ) ;
117
119
f. write ( ": " ) ;
118
120
arg. 1 . display ( f) ;
119
121
}
120
- f. write ( ")" ) ;
122
+ f. end_argument_block ( ')' ) ;
121
123
}
122
124
}
123
125
124
- impl < ' a , T : Text < ' a > > Displayable for Field < ' a , T >
126
+ impl < ' a , T : Text < ' a > > Displayable for Field < ' a , T >
125
127
where T : Text < ' a > ,
126
128
{
127
129
fn display ( & self , f : & mut Formatter ) {
@@ -146,7 +148,7 @@ impl<'a, T: Text<'a>> Displayable for Field<'a, T>
146
148
}
147
149
}
148
150
149
- impl < ' a , T : Text < ' a > > Displayable for Query < ' a , T >
151
+ impl < ' a , T : Text < ' a > > Displayable for Query < ' a , T >
150
152
where T : Text < ' a > ,
151
153
{
152
154
fn display ( & self , f : & mut Formatter ) {
@@ -176,7 +178,7 @@ impl<'a, T: Text<'a>> Displayable for Query<'a, T>
176
178
}
177
179
}
178
180
179
- impl < ' a , T : Text < ' a > > Displayable for Mutation < ' a , T >
181
+ impl < ' a , T : Text < ' a > > Displayable for Mutation < ' a , T >
180
182
where T : Text < ' a > ,
181
183
{
182
184
fn display ( & self , f : & mut Formatter ) {
@@ -206,7 +208,7 @@ impl<'a, T: Text<'a>> Displayable for Mutation<'a, T>
206
208
}
207
209
}
208
210
209
- impl < ' a , T : Text < ' a > > Displayable for Subscription < ' a , T >
211
+ impl < ' a , T : Text < ' a > > Displayable for Subscription < ' a , T >
210
212
where T : Text < ' a > ,
211
213
{
212
214
fn display ( & self , f : & mut Formatter ) {
@@ -234,7 +236,7 @@ impl<'a, T: Text<'a>> Displayable for Subscription<'a, T>
234
236
}
235
237
}
236
238
237
- impl < ' a , T : Text < ' a > > Displayable for VariableDefinition < ' a , T >
239
+ impl < ' a , T : Text < ' a > > Displayable for VariableDefinition < ' a , T >
238
240
where T : Text < ' a > ,
239
241
{
240
242
fn display ( & self , f : & mut Formatter ) {
@@ -249,7 +251,7 @@ impl<'a, T: Text<'a>> Displayable for VariableDefinition<'a, T>
249
251
}
250
252
}
251
253
252
- impl < ' a , T : Text < ' a > > Displayable for Type < ' a , T >
254
+ impl < ' a , T : Text < ' a > > Displayable for Type < ' a , T >
253
255
where T : Text < ' a > ,
254
256
{
255
257
fn display ( & self , f : & mut Formatter ) {
@@ -268,12 +270,15 @@ impl<'a, T: Text<'a>> Displayable for Type<'a, T>
268
270
}
269
271
}
270
272
271
- impl < ' a , T : Text < ' a > > Displayable for Value < ' a , T >
273
+ impl < ' a , T : Text < ' a > > Displayable for Value < ' a , T >
272
274
where T : Text < ' a > ,
273
275
{
274
276
fn display ( & self , f : & mut Formatter ) {
275
277
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
+ }
277
282
Value :: Int ( ref num) => f. write ( & format ! ( "{}" , num. 0 ) ) ,
278
283
Value :: Float ( val) => f. write ( & format ! ( "{}" , val) ) ,
279
284
Value :: String ( ref val) => f. write_quoted ( val) ,
@@ -282,36 +287,39 @@ impl<'a, T: Text<'a>> Displayable for Value<'a, T>
282
287
Value :: Null => f. write ( "null" ) ,
283
288
Value :: Enum ( ref name) => f. write ( name. as_ref ( ) ) ,
284
289
Value :: List ( ref items) => {
285
- f. write ( "[" ) ;
290
+ f. start_argument_block ( '[' ) ;
286
291
if !items. is_empty ( ) {
292
+ f. start_argument ( ) ;
287
293
items[ 0 ] . display ( f) ;
288
294
for item in & items[ 1 ..] {
289
- f. write ( ", " ) ;
295
+ f. deliniate_argument ( ) ;
296
+ f. start_argument ( ) ;
290
297
item. display ( f) ;
291
298
}
292
299
}
293
- f. write ( "]" ) ;
300
+ f. end_argument_block ( ']' ) ;
294
301
}
295
302
Value :: Object ( ref items) => {
296
- f. write ( "{" ) ;
303
+ f. start_argument_block ( '{' ) ;
297
304
let mut first = true ;
298
305
for ( name, value) in items. iter ( ) {
299
306
if first {
300
307
first = false ;
301
308
} else {
302
- f. write ( ", " ) ;
309
+ f. deliniate_argument ( ) ;
303
310
}
311
+ f. start_argument ( ) ;
304
312
f. write ( name. as_ref ( ) ) ;
305
313
f. write ( ": " ) ;
306
314
value. display ( f) ;
307
315
}
308
- f. write ( "}" ) ;
316
+ f. end_argument_block ( '}' ) ;
309
317
}
310
318
}
311
319
}
312
320
}
313
321
314
- impl < ' a , T : Text < ' a > > Displayable for InlineFragment < ' a , T >
322
+ impl < ' a , T : Text < ' a > > Displayable for InlineFragment < ' a , T >
315
323
where T : Text < ' a > ,
316
324
{
317
325
fn display ( & self , f : & mut Formatter ) {
@@ -331,7 +339,7 @@ impl<'a, T: Text<'a>> Displayable for InlineFragment<'a, T>
331
339
}
332
340
}
333
341
334
- impl < ' a , T : Text < ' a > > Displayable for TypeCondition < ' a , T >
342
+ impl < ' a , T : Text < ' a > > Displayable for TypeCondition < ' a , T >
335
343
where T : Text < ' a > ,
336
344
{
337
345
fn display ( & self , f : & mut Formatter ) {
@@ -344,7 +352,7 @@ impl<'a, T: Text<'a>> Displayable for TypeCondition<'a, T>
344
352
}
345
353
}
346
354
347
- impl < ' a , T : Text < ' a > > Displayable for FragmentSpread < ' a , T >
355
+ impl < ' a , T : Text < ' a > > Displayable for FragmentSpread < ' a , T >
348
356
where T : Text < ' a > ,
349
357
{
350
358
fn display ( & self , f : & mut Formatter ) {
@@ -356,7 +364,7 @@ impl<'a, T: Text<'a>> Displayable for FragmentSpread<'a, T>
356
364
}
357
365
}
358
366
359
- impl < ' a , T : Text < ' a > > Displayable for Directive < ' a , T >
367
+ impl < ' a , T : Text < ' a > > Displayable for Directive < ' a , T >
360
368
where T : Text < ' a > ,
361
369
{
362
370
fn display ( & self , f : & mut Formatter ) {
@@ -366,9 +374,8 @@ impl<'a, T: Text<'a>> Displayable for Directive<'a, T>
366
374
}
367
375
}
368
376
369
-
370
377
impl_display ! (
371
- ' a
378
+ ' a
372
379
Document ,
373
380
Definition ,
374
381
OperationDefinition ,
0 commit comments