@@ -246,7 +246,7 @@ use serialize::Encodable;
246
246
use serialize;
247
247
use collections:: TreeMap ;
248
248
249
- macro_rules! if_ok ( ( $e: expr) => (
249
+ macro_rules! try ( ( $e: expr) => (
250
250
match $e { Ok ( e) => e, Err ( e) => { self . error = Err ( e) ; return } }
251
251
) )
252
252
@@ -342,7 +342,7 @@ impl<'a> Encoder<'a> {
342
342
}
343
343
344
344
impl < ' a > serialize:: Encoder for Encoder < ' a > {
345
- fn emit_nil ( & mut self ) { if_ok ! ( write!( self . wr, "null" ) ) }
345
+ fn emit_nil ( & mut self ) { try !( write ! ( self . wr, "null" ) ) }
346
346
347
347
fn emit_uint ( & mut self , v : uint ) { self . emit_f64 ( v as f64 ) ; }
348
348
fn emit_u64 ( & mut self , v : u64 ) { self . emit_f64 ( v as f64 ) ; }
@@ -358,20 +358,20 @@ impl<'a> serialize::Encoder for Encoder<'a> {
358
358
359
359
fn emit_bool ( & mut self , v : bool ) {
360
360
if v {
361
- if_ok ! ( write!( self . wr, "true" ) ) ;
361
+ try !( write ! ( self . wr, "true" ) ) ;
362
362
} else {
363
- if_ok ! ( write!( self . wr, "false" ) ) ;
363
+ try !( write ! ( self . wr, "false" ) ) ;
364
364
}
365
365
}
366
366
367
367
fn emit_f64 ( & mut self , v : f64 ) {
368
- if_ok ! ( write!( self . wr, "{}" , f64 :: to_str_digits( v, 6 u) ) )
368
+ try !( write ! ( self . wr, "{}" , f64 :: to_str_digits( v, 6 u) ) )
369
369
}
370
370
fn emit_f32 ( & mut self , v : f32 ) { self . emit_f64 ( v as f64 ) ; }
371
371
372
372
fn emit_char ( & mut self , v : char ) { self . emit_str ( str:: from_char ( v) ) }
373
373
fn emit_str ( & mut self , v : & str ) {
374
- if_ok ! ( write!( self . wr, "{}" , escape_str( v) ) )
374
+ try !( write ! ( self . wr, "{}" , escape_str( v) ) )
375
375
}
376
376
377
377
fn emit_enum ( & mut self , _name : & str , f: |& mut Encoder < ' a > |) { f( self ) }
@@ -385,19 +385,19 @@ impl<'a> serialize::Encoder for Encoder<'a> {
385
385
// Bunny => "Bunny"
386
386
// Kangaroo(34,"William") => {"variant": "Kangaroo", "fields": [34,"William"]}
387
387
if cnt == 0 {
388
- if_ok ! ( write!( self . wr, "{}" , escape_str( name) ) ) ;
388
+ try !( write ! ( self . wr, "{}" , escape_str( name) ) ) ;
389
389
} else {
390
- if_ok ! ( write!( self . wr, "\\ {\" variant\" :" ) ) ;
391
- if_ok ! ( write!( self . wr, "{}" , escape_str( name) ) ) ;
392
- if_ok ! ( write!( self . wr, ",\" fields\" :[" ) ) ;
390
+ try !( write ! ( self . wr, "\\ {\" variant\" :" ) ) ;
391
+ try !( write ! ( self . wr, "{}" , escape_str( name) ) ) ;
392
+ try !( write ! ( self . wr, ",\" fields\" :[" ) ) ;
393
393
f( self ) ;
394
- if_ok ! ( write!( self . wr, "]\\ }" ) ) ;
394
+ try !( write ! ( self . wr, "]\\ }" ) ) ;
395
395
}
396
396
}
397
397
398
398
fn emit_enum_variant_arg( & mut self , idx: uint, f: |& mut Encoder < ' a > |) {
399
399
if idx != 0 {
400
- if_ok ! ( write!( self . wr, "," ) ) ;
400
+ try !( write ! ( self . wr, "," ) ) ;
401
401
}
402
402
f( self ) ;
403
403
}
@@ -418,17 +418,17 @@ impl<'a> serialize::Encoder for Encoder<'a> {
418
418
}
419
419
420
420
fn emit_struct( & mut self , _: & str, _: uint, f: |& mut Encoder < ' a > |) {
421
- if_ok ! ( write!( self . wr, r"\{" ) ) ;
421
+ try !( write ! ( self . wr, r"\{" ) ) ;
422
422
f( self ) ;
423
- if_ok ! ( write!( self . wr, r"\}" ) ) ;
423
+ try !( write ! ( self . wr, r"\}" ) ) ;
424
424
}
425
425
426
426
fn emit_struct_field( & mut self ,
427
427
name: & str,
428
428
idx: uint,
429
429
f: |& mut Encoder < ' a > |) {
430
- if idx != 0 { if_ok ! ( write!( self . wr, "," ) ) }
431
- if_ok ! ( write!( self . wr, "{}:" , escape_str( name) ) ) ;
430
+ if idx != 0 { try !( write ! ( self . wr, "," ) ) }
431
+ try !( write ! ( self . wr, "{}:" , escape_str( name) ) ) ;
432
432
f( self ) ;
433
433
}
434
434
@@ -454,31 +454,31 @@ impl<'a> serialize::Encoder for Encoder<'a> {
454
454
fn emit_option_some( & mut self , f: |& mut Encoder < ' a > |) { f( self ) ; }
455
455
456
456
fn emit_seq( & mut self , _len: uint, f: |& mut Encoder < ' a > |) {
457
- if_ok ! ( write!( self . wr, "[" ) ) ;
457
+ try !( write ! ( self . wr, "[" ) ) ;
458
458
f( self ) ;
459
- if_ok ! ( write!( self . wr, "]" ) ) ;
459
+ try !( write ! ( self . wr, "]" ) ) ;
460
460
}
461
461
462
462
fn emit_seq_elt( & mut self , idx: uint, f: |& mut Encoder < ' a > |) {
463
463
if idx != 0 {
464
- if_ok ! ( write!( self . wr, "," ) ) ;
464
+ try !( write ! ( self . wr, "," ) ) ;
465
465
}
466
466
f( self )
467
467
}
468
468
469
469
fn emit_map( & mut self , _len: uint, f: |& mut Encoder < ' a > |) {
470
- if_ok ! ( write!( self . wr, r"\{" ) ) ;
470
+ try !( write ! ( self . wr, r"\{" ) ) ;
471
471
f( self ) ;
472
- if_ok ! ( write!( self . wr, r"\}" ) ) ;
472
+ try !( write ! ( self . wr, r"\}" ) ) ;
473
473
}
474
474
475
475
fn emit_map_elt_key( & mut self , idx: uint, f: |& mut Encoder < ' a > |) {
476
- if idx != 0 { if_ok ! ( write!( self . wr, "," ) ) }
476
+ if idx != 0 { try !( write ! ( self . wr, "," ) ) }
477
477
f( self )
478
478
}
479
479
480
480
fn emit_map_elt_val( & mut self , _idx: uint, f: |& mut Encoder < ' a > |) {
481
- if_ok ! ( write!( self . wr, ":" ) ) ;
481
+ try !( write ! ( self . wr, ":" ) ) ;
482
482
f( self )
483
483
}
484
484
}
@@ -503,7 +503,7 @@ impl<'a> PrettyEncoder<'a> {
503
503
}
504
504
505
505
impl <' a> serialize:: Encoder for PrettyEncoder < ' a > {
506
- fn emit_nil( & mut self ) { if_ok ! ( write!( self . wr, "null" ) ) ; }
506
+ fn emit_nil( & mut self ) { try !( write ! ( self . wr, "null" ) ) ; }
507
507
508
508
fn emit_uint( & mut self , v: uint) { self . emit_f64( v as f64) ; }
509
509
fn emit_u64( & mut self , v: u64) { self . emit_f64( v as f64) ; }
@@ -519,20 +519,20 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
519
519
520
520
fn emit_bool( & mut self , v: bool) {
521
521
if v {
522
- if_ok !( write ! ( self . wr, "true" ) ) ;
522
+ try !( write ! ( self . wr, "true" ) ) ;
523
523
} else {
524
- if_ok ! ( write!( self . wr, "false" ) ) ;
524
+ try !( write ! ( self . wr, "false" ) ) ;
525
525
}
526
526
}
527
527
528
528
fn emit_f64( & mut self , v: f64) {
529
- if_ok ! ( write!( self . wr, "{}" , f64 :: to_str_digits( v, 6 u) ) ) ;
529
+ try !( write ! ( self . wr, "{}" , f64 :: to_str_digits( v, 6 u) ) ) ;
530
530
}
531
531
fn emit_f32( & mut self , v: f32) { self . emit_f64( v as f64) ; }
532
532
533
533
fn emit_char( & mut self , v: char) { self . emit_str( str:: from_char( v) ) }
534
534
fn emit_str( & mut self , v: & str) {
535
- if_ok ! ( write!( self . wr, "{}" , escape_str( v) ) ) ;
535
+ try !( write ! ( self . wr, "{}" , escape_str( v) ) ) ;
536
536
}
537
537
538
538
fn emit_enum( & mut self , _name: & str, f: |& mut PrettyEncoder < ' a > |) {
@@ -545,24 +545,24 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
545
545
cnt: uint,
546
546
f: |& mut PrettyEncoder < ' a > |) {
547
547
if cnt == 0 {
548
- if_ok ! ( write!( self . wr, "{}" , escape_str( name) ) ) ;
548
+ try !( write ! ( self . wr, "{}" , escape_str( name) ) ) ;
549
549
} else {
550
550
self . indent += 2 ;
551
- if_ok ! ( write!( self . wr, "[\n {}{},\n " , spaces( self . indent) ,
551
+ try !( write ! ( self . wr, "[\n {}{},\n " , spaces( self . indent) ,
552
552
escape_str( name) ) ) ;
553
553
f( self ) ;
554
554
self . indent -= 2 ;
555
- if_ok ! ( write!( self . wr, "\n {}]" , spaces( self . indent) ) ) ;
555
+ try !( write ! ( self . wr, "\n {}]" , spaces( self . indent) ) ) ;
556
556
}
557
557
}
558
558
559
559
fn emit_enum_variant_arg( & mut self ,
560
560
idx: uint,
561
561
f: |& mut PrettyEncoder < ' a > |) {
562
562
if idx != 0 {
563
- if_ok ! ( write!( self . wr, ",\n " ) ) ;
563
+ try !( write ! ( self . wr, ",\n " ) ) ;
564
564
}
565
- if_ok ! ( write!( self . wr, "{}" , spaces( self . indent) ) ) ;
565
+ try !( write ! ( self . wr, "{}" , spaces( self . indent) ) ) ;
566
566
f( self )
567
567
}
568
568
@@ -587,13 +587,13 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
587
587
len: uint,
588
588
f: |& mut PrettyEncoder < ' a > |) {
589
589
if len == 0 {
590
- if_ok ! ( write!( self . wr, "\\ {\\ }" ) ) ;
590
+ try !( write ! ( self . wr, "\\ {\\ }" ) ) ;
591
591
} else {
592
- if_ok ! ( write!( self . wr, "\\ {" ) ) ;
592
+ try !( write ! ( self . wr, "\\ {" ) ) ;
593
593
self . indent += 2 ;
594
594
f( self ) ;
595
595
self . indent -= 2 ;
596
- if_ok ! ( write!( self . wr, "\n {}\\ }" , spaces( self . indent) ) ) ;
596
+ try !( write ! ( self . wr, "\n {}\\ }" , spaces( self . indent) ) ) ;
597
597
}
598
598
}
599
599
@@ -602,11 +602,11 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
602
602
idx: uint,
603
603
f: |& mut PrettyEncoder < ' a > |) {
604
604
if idx == 0 {
605
- if_ok ! ( write!( self . wr, "\n " ) ) ;
605
+ try !( write ! ( self . wr, "\n " ) ) ;
606
606
} else {
607
- if_ok ! ( write!( self . wr, ",\n " ) ) ;
607
+ try !( write ! ( self . wr, ",\n " ) ) ;
608
608
}
609
- if_ok ! ( write!( self . wr, "{}{}: " , spaces( self . indent) , escape_str( name) ) ) ;
609
+ try !( write ! ( self . wr, "{}{}: " , spaces( self . indent) , escape_str( name) ) ) ;
610
610
f( self ) ;
611
611
}
612
612
@@ -635,50 +635,50 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
635
635
636
636
fn emit_seq( & mut self , len: uint, f: |& mut PrettyEncoder < ' a > |) {
637
637
if len == 0 {
638
- if_ok ! ( write!( self . wr, "[]" ) ) ;
638
+ try !( write ! ( self . wr, "[]" ) ) ;
639
639
} else {
640
- if_ok ! ( write!( self . wr, "[" ) ) ;
640
+ try !( write ! ( self . wr, "[" ) ) ;
641
641
self . indent += 2 ;
642
642
f( self ) ;
643
643
self . indent -= 2 ;
644
- if_ok ! ( write!( self . wr, "\n {}]" , spaces( self . indent) ) ) ;
644
+ try !( write ! ( self . wr, "\n {}]" , spaces( self . indent) ) ) ;
645
645
}
646
646
}
647
647
648
648
fn emit_seq_elt( & mut self , idx: uint, f: |& mut PrettyEncoder < ' a > |) {
649
649
if idx == 0 {
650
- if_ok ! ( write!( self . wr, "\n " ) ) ;
650
+ try !( write ! ( self . wr, "\n " ) ) ;
651
651
} else {
652
- if_ok ! ( write!( self . wr, ",\n " ) ) ;
652
+ try !( write ! ( self . wr, ",\n " ) ) ;
653
653
}
654
- if_ok ! ( write!( self . wr, "{}" , spaces( self . indent) ) ) ;
654
+ try !( write ! ( self . wr, "{}" , spaces( self . indent) ) ) ;
655
655
f( self )
656
656
}
657
657
658
658
fn emit_map( & mut self , len: uint, f: |& mut PrettyEncoder < ' a > |) {
659
659
if len == 0 {
660
- if_ok ! ( write!( self . wr, "\\ {\\ }" ) ) ;
660
+ try !( write ! ( self . wr, "\\ {\\ }" ) ) ;
661
661
} else {
662
- if_ok ! ( write!( self . wr, "\\ {" ) ) ;
662
+ try !( write ! ( self . wr, "\\ {" ) ) ;
663
663
self . indent += 2 ;
664
664
f( self ) ;
665
665
self . indent -= 2 ;
666
- if_ok ! ( write!( self . wr, "\n {}\\ }" , spaces( self . indent) ) ) ;
666
+ try !( write ! ( self . wr, "\n {}\\ }" , spaces( self . indent) ) ) ;
667
667
}
668
668
}
669
669
670
670
fn emit_map_elt_key( & mut self , idx: uint, f: |& mut PrettyEncoder < ' a > |) {
671
671
if idx == 0 {
672
- if_ok ! ( write!( self . wr, "\n " ) ) ;
672
+ try !( write ! ( self . wr, "\n " ) ) ;
673
673
} else {
674
- if_ok ! ( write!( self . wr, ",\n " ) ) ;
674
+ try !( write ! ( self . wr, ",\n " ) ) ;
675
675
}
676
- if_ok ! ( write!( self . wr, "{}" , spaces( self . indent) ) ) ;
676
+ try !( write ! ( self . wr, "{}" , spaces( self . indent) ) ) ;
677
677
f( self ) ;
678
678
}
679
679
680
680
fn emit_map_elt_val( & mut self , _idx: uint, f: |& mut PrettyEncoder < ' a > |) {
681
- if_ok ! ( write!( self . wr, ": " ) ) ;
681
+ try !( write ! ( self . wr, ": " ) ) ;
682
682
f ( self ) ;
683
683
}
684
684
}
0 commit comments