@@ -234,7 +234,7 @@ impl JsonEmitter {
234
234
235
235
fn emit_bytes < W : fmt:: Write > ( & mut self , w : & mut W , bytes : & [ u8 ] ) -> Result < ( ) > {
236
236
self . level += 1 ;
237
- self . writeln ( w, & self . color . aggregate . paint ( "[" ) . to_string ( ) ) ?;
237
+ self . writeln ( w, self . color . aggregate . paint ( "[" ) ) ?;
238
238
self . emit_indent ( w) ?;
239
239
for ( i, value) in bytes. iter ( ) . enumerate ( ) {
240
240
if i > 0 {
@@ -250,14 +250,14 @@ impl JsonEmitter {
250
250
self . writeln ( w, "" ) ?;
251
251
self . level -= 1 ;
252
252
self . emit_indent ( w) ?;
253
- write ! ( w, "{}" , & self . color. aggregate. paint( "]" ) ) ?;
253
+ write ! ( w, "{}" , self . color. aggregate. paint( "]" ) ) ?;
254
254
Ok ( ( ) )
255
255
}
256
256
257
257
// TODO: Can this function be rewritten to be less complex?
258
258
fn emit_sequence < W : fmt:: Write > ( & mut self , w : & mut W , sequence : & [ Document ] ) -> Result < ( ) > {
259
259
self . level += 1 ;
260
- self . writeln ( w, & self . color . aggregate . paint ( "[" ) . to_string ( ) ) ?;
260
+ self . writeln ( w, self . color . aggregate . paint ( "[" ) ) ?;
261
261
if !sequence. is_empty ( ) {
262
262
self . emit_indent ( w) ?;
263
263
}
@@ -289,7 +289,7 @@ impl JsonEmitter {
289
289
if !val_done {
290
290
self . emit_node ( w, node) ?;
291
291
if i != last {
292
- write ! ( w, "{}" , & self . color. punctuation. paint( "," ) ) ?;
292
+ write ! ( w, "{}" , self . color. punctuation. paint( "," ) ) ?;
293
293
}
294
294
val_done = true ;
295
295
need_eol = true ;
@@ -300,7 +300,7 @@ impl JsonEmitter {
300
300
} else {
301
301
self . emit_node ( w, value) ?;
302
302
if i != last {
303
- write ! ( w, "{}" , & self . color. punctuation. paint( "," ) ) ?;
303
+ write ! ( w, "{}" , self . color. punctuation. paint( "," ) ) ?;
304
304
}
305
305
need_eol = true ;
306
306
}
@@ -310,7 +310,7 @@ impl JsonEmitter {
310
310
}
311
311
self . level -= 1 ;
312
312
self . emit_indent ( w) ?;
313
- write ! ( w, "{}" , & self . color. aggregate. paint( "]" ) ) ?;
313
+ write ! ( w, "{}" , self . color. aggregate. paint( "]" ) ) ?;
314
314
Ok ( ( ) )
315
315
}
316
316
@@ -332,7 +332,7 @@ impl JsonEmitter {
332
332
// TODO: Can this function be rewritten to be less complex?
333
333
fn emit_mapping < W : fmt:: Write > ( & mut self , w : & mut W , mapping : & [ Document ] ) -> Result < ( ) > {
334
334
self . level += 1 ;
335
- self . writeln ( w, & self . color . aggregate . paint ( "{" ) . to_string ( ) ) ?;
335
+ self . writeln ( w, self . color . aggregate . paint ( "{" ) ) ?;
336
336
if !mapping. is_empty ( ) {
337
337
self . emit_indent ( w) ?;
338
338
}
@@ -370,21 +370,21 @@ impl JsonEmitter {
370
370
w,
371
371
"{}{}{}" ,
372
372
self . color. punctuation. paint( "\" " ) ,
373
- self . color. key. paint( format! ( "{}" , v ) ) ,
373
+ self . color. key. paint( v ) ,
374
374
self . color. punctuation. paint( "\" " )
375
375
) ?,
376
376
Document :: Int ( v) => write ! (
377
377
w,
378
378
"{}{}{}" ,
379
379
self . color. punctuation. paint( "\" " ) ,
380
- self . color. key. paint( format! ( "{}" , v ) ) ,
380
+ self . color. key. paint( v ) ,
381
381
self . color. punctuation. paint( "\" " )
382
382
) ?,
383
383
Document :: Float ( v) => write ! (
384
384
w,
385
385
"{}{}{}" ,
386
386
self . color. punctuation. paint( "\" " ) ,
387
- self . color. key. paint( format! ( "{}" , v ) ) ,
387
+ self . color. key. paint( v ) ,
388
388
self . color. punctuation. paint( "\" " )
389
389
) ?,
390
390
Document :: Comment ( _, _) => return Err ( Error :: KeyTypeError ( "comment" ) ) ,
@@ -395,12 +395,12 @@ impl JsonEmitter {
395
395
Document :: Fragment ( _) => return Err ( Error :: KeyTypeError ( "fragment" ) ) ,
396
396
Document :: Null => return Err ( Error :: KeyTypeError ( "null" ) ) ,
397
397
} ;
398
- write ! ( w, "{}" , & self . color. punctuation. paint( ": " ) ) ?;
398
+ write ! ( w, "{}" , self . color. punctuation. paint( ": " ) ) ?;
399
399
key_done = true ;
400
400
} else if !val_done {
401
401
self . emit_node ( w, node) ?;
402
402
if i != last {
403
- write ! ( w, "{}" , & self . color. punctuation. paint( "," ) ) ?;
403
+ write ! ( w, "{}" , self . color. punctuation. paint( "," ) ) ?;
404
404
}
405
405
val_done = true ;
406
406
need_eol = true ;
@@ -412,7 +412,7 @@ impl JsonEmitter {
412
412
}
413
413
self . level -= 1 ;
414
414
self . emit_indent ( w) ?;
415
- write ! ( w, "{}" , & self . color. aggregate. paint( "}" ) ) ?;
415
+ write ! ( w, "{}" , self . color. aggregate. paint( "}" ) ) ?;
416
416
Ok ( ( ) )
417
417
}
418
418
@@ -459,7 +459,9 @@ impl JsonEmitter {
459
459
write ! (
460
460
w,
461
461
"{}" ,
462
- self . color. comment. paint( format!( "{} {}" , leader, line) )
462
+ self . color
463
+ . comment
464
+ . paint( format_args!( "{} {}" , leader, line) )
463
465
) ?;
464
466
}
465
467
}
@@ -479,7 +481,7 @@ impl JsonEmitter {
479
481
}
480
482
481
483
fn emit_string_strict < W : fmt:: Write > ( & mut self , w : & mut W , value : & str ) -> Result < ( ) > {
482
- write ! ( w, "{}" , & self . color. punctuation. paint( "\" " ) ) ?;
484
+ write ! ( w, "{}" , self . color. punctuation. paint( "\" " ) ) ?;
483
485
let bytes = value. as_bytes ( ) ;
484
486
let mut start = 0 ;
485
487
for ( i, & byte) in bytes. iter ( ) . enumerate ( ) {
@@ -488,26 +490,28 @@ impl JsonEmitter {
488
490
continue ;
489
491
}
490
492
if start < i {
491
- write ! ( w, "{}" , & self . color. string. paint( & value[ start..i] ) ) ?;
493
+ write ! ( w, "{}" , self . color. string. paint( & value[ start..i] ) ) ?;
492
494
}
493
495
match escape {
494
496
UU => write ! (
495
497
w,
496
498
"{}" ,
497
- & self . color. escape. paint( format !( "\\ u{:04x}" , byte) )
499
+ self . color. escape. paint( format_args !( "\\ u{:04x}" , byte) )
498
500
) ?,
499
501
_ => write ! (
500
502
w,
501
503
"{}" ,
502
- & self . color. escape. paint( format!( "\\ {}" , escape as char ) )
504
+ self . color
505
+ . escape
506
+ . paint( format_args!( "\\ {}" , escape as char ) )
503
507
) ?,
504
508
} ;
505
509
start = i + 1 ;
506
510
}
507
511
if start != bytes. len ( ) {
508
- write ! ( w, "{}" , & self . color. string. paint( & value[ start..] ) ) ?;
512
+ write ! ( w, "{}" , self . color. string. paint( & value[ start..] ) ) ?;
509
513
}
510
- write ! ( w, "{}" , & self . color. punctuation. paint( "\" " ) ) ?;
514
+ write ! ( w, "{}" , self . color. punctuation. paint( "\" " ) ) ?;
511
515
Ok ( ( ) )
512
516
}
513
517
@@ -516,10 +520,10 @@ impl JsonEmitter {
516
520
writeln ! ( w) ?;
517
521
self . level += 1 ;
518
522
self . emit_indent ( w) ?;
519
- self . writeln ( w, & self . color . punctuation . paint ( "'''" ) . to_string ( ) ) ?;
523
+ self . writeln ( w, self . color . punctuation . paint ( "'''" ) ) ?;
520
524
self . emit_indent ( w) ?;
521
525
} else {
522
- write ! ( w, "{}" , & self . color. punctuation. paint( "\" " ) ) ?;
526
+ write ! ( w, "{}" , self . color. punctuation. paint( "\" " ) ) ?;
523
527
}
524
528
let bytes = value. as_bytes ( ) ;
525
529
let mut start = 0 ;
@@ -529,19 +533,21 @@ impl JsonEmitter {
529
533
continue ;
530
534
}
531
535
if start < i {
532
- write ! ( w, "{}" , & self . color. string. paint( & value[ start..i] ) ) ?;
536
+ write ! ( w, "{}" , self . color. string. paint( & value[ start..i] ) ) ?;
533
537
}
534
538
match escape {
535
539
UU => write ! (
536
540
w,
537
541
"{}" ,
538
- & self . color. escape. paint( format !( "\\ u{:04x}" , byte) )
542
+ self . color. escape. paint( format_args !( "\\ u{:04x}" , byte) )
539
543
) ?,
540
544
NN => match self . multiline {
541
545
Multiline :: None => write ! (
542
546
w,
543
547
"{}" ,
544
- & self . color. escape. paint( format!( "\\ {}" , escape as char ) )
548
+ self . color
549
+ . escape
550
+ . paint( format_args!( "\\ {}" , escape as char ) )
545
551
) ?,
546
552
Multiline :: Json5 => writeln ! ( w, "{}" , self . color. escape. paint( "\\ " ) ) ?,
547
553
Multiline :: Hjson => {
@@ -552,30 +558,32 @@ impl JsonEmitter {
552
558
_ => write ! (
553
559
w,
554
560
"{}" ,
555
- & self . color. escape. paint( format!( "\\ {}" , escape as char ) )
561
+ self . color
562
+ . escape
563
+ . paint( format_args!( "\\ {}" , escape as char ) )
556
564
) ?,
557
565
} ;
558
566
start = i + 1 ;
559
567
}
560
568
if start != bytes. len ( ) {
561
- write ! ( w, "{}" , & self . color. string. paint( & value[ start..] ) ) ?;
569
+ write ! ( w, "{}" , self . color. string. paint( & value[ start..] ) ) ?;
562
570
}
563
571
if self . multiline == Multiline :: Hjson {
564
572
writeln ! ( w) ?;
565
573
self . emit_indent ( w) ?;
566
- write ! ( w, "{}" , & self . color. punctuation. paint( "'''" ) ) ?;
574
+ write ! ( w, "{}" , self . color. punctuation. paint( "'''" ) ) ?;
567
575
self . level -= 1 ;
568
576
} else {
569
- write ! ( w, "{}" , & self . color. punctuation. paint( "\" " ) ) ?;
577
+ write ! ( w, "{}" , self . color. punctuation. paint( "\" " ) ) ?;
570
578
}
571
579
Ok ( ( ) )
572
580
}
573
581
574
582
fn emit_boolean < W : fmt:: Write > ( & mut self , w : & mut W , b : bool ) -> Result < ( ) > {
575
583
if b {
576
- write ! ( w, "{}" , & self . color. boolean. paint( "true" ) ) ?;
584
+ write ! ( w, "{}" , self . color. boolean. paint( "true" ) ) ?;
577
585
} else {
578
- write ! ( w, "{}" , & self . color. boolean. paint( "false" ) ) ?;
586
+ write ! ( w, "{}" , self . color. boolean. paint( "false" ) ) ?;
579
587
}
580
588
Ok ( ( ) )
581
589
}
@@ -594,18 +602,18 @@ impl JsonEmitter {
594
602
self . color. punctuation. paint( "\" " )
595
603
) ?;
596
604
} else {
597
- write ! ( w, "{}" , & self . color. integer. paint( s) ) ?;
605
+ write ! ( w, "{}" , self . color. integer. paint( s) ) ?;
598
606
}
599
607
Ok ( ( ) )
600
608
}
601
609
602
610
fn emit_float < W : fmt:: Write > ( & mut self , w : & mut W , f : f64 ) -> Result < ( ) > {
603
- write ! ( w, "{}" , & self . color. float. paint( format! ( "{}" , f ) ) ) ?;
611
+ write ! ( w, "{}" , self . color. float. paint( f ) ) ?;
604
612
Ok ( ( ) )
605
613
}
606
614
607
615
fn emit_null < W : fmt:: Write > ( & mut self , w : & mut W ) -> Result < ( ) > {
608
- write ! ( w, "{}" , & self . color. null. paint( "null" ) ) ?;
616
+ write ! ( w, "{}" , self . color. null. paint( "null" ) ) ?;
609
617
Ok ( ( ) )
610
618
}
611
619
0 commit comments