@@ -75,35 +75,50 @@ impl Repr for bool {
75
75
}
76
76
}
77
77
78
- macro_rules! int_repr( ( $ty: ident) => ( impl Repr for $ty {
78
+ impl Repr for int {
79
+ fn write_repr ( & self , writer : @Writer ) {
80
+ do :: int:: to_str_bytes ( * self , 10 u) |bits| {
81
+ writer. write ( bits) ;
82
+ }
83
+ }
84
+ }
85
+
86
+ macro_rules! int_repr( ( $ty: ident, $suffix: expr) => ( impl Repr for $ty {
79
87
fn write_repr( & self , writer: @Writer ) {
80
88
do :: $ty:: to_str_bytes( * self , 10 u) |bits| {
81
89
writer. write( bits) ;
90
+ writer. write( bytes!( $suffix) ) ;
82
91
}
83
92
}
84
93
} ) )
85
94
86
- int_repr ! ( int)
87
- int_repr ! ( i8 )
88
- int_repr ! ( i16 )
89
- int_repr ! ( i32 )
90
- int_repr ! ( i64 )
91
- int_repr ! ( uint)
92
- int_repr ! ( u8 )
93
- int_repr ! ( u16 )
94
- int_repr ! ( u32 )
95
- int_repr ! ( u64 )
96
-
97
- macro_rules! num_repr( ( $ty: ident) => ( impl Repr for $ty {
95
+ int_repr ! ( i8 , "i8" )
96
+ int_repr ! ( i16 , "i16" )
97
+ int_repr ! ( i32 , "i32" )
98
+ int_repr ! ( i64 , "i64" )
99
+ int_repr ! ( uint, "u" )
100
+ int_repr ! ( u8 , "u8" )
101
+ int_repr ! ( u16 , "u16" )
102
+ int_repr ! ( u32 , "u32" )
103
+ int_repr ! ( u64 , "u64" )
104
+
105
+ impl Repr for float {
106
+ fn write_repr ( & self , writer : @Writer ) {
107
+ let s = self . to_str ( ) ;
108
+ writer. write ( s. as_bytes ( ) ) ;
109
+ }
110
+ }
111
+
112
+ macro_rules! num_repr( ( $ty: ident, $suffix: expr) => ( impl Repr for $ty {
98
113
fn write_repr( & self , writer: @Writer ) {
99
114
let s = self . to_str( ) ;
100
115
writer. write( s. as_bytes( ) ) ;
116
+ writer. write( bytes!( $suffix) ) ;
101
117
}
102
118
} ) )
103
119
104
- num_repr ! ( float)
105
- num_repr ! ( f32 )
106
- num_repr ! ( f64 )
120
+ num_repr ! ( f32 , "f32" )
121
+ num_repr ! ( f64 , "f64" )
107
122
108
123
// New implementation using reflect::MovePtr
109
124
@@ -602,7 +617,7 @@ fn test_repr() {
602
617
exact_test ( & ( @[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ,
603
618
"@[1, 2, 3, 4, 5, 6, 7, 8]" ) ;
604
619
exact_test ( & ( @[ 1u8 , 2u8 , 3u8 , 4u8 ] ) ,
605
- "@[1, 2, 3, 4 ]" ) ;
620
+ "@[1u8, 2u8, 3u8, 4u8 ]" ) ;
606
621
exact_test ( & ( @[ "hi" , "there" ] ) ,
607
622
"@[\" hi\" , \" there\" ]" ) ;
608
623
exact_test ( & ( ~[ "hi" , "there" ] ) ,
@@ -615,14 +630,14 @@ fn test_repr() {
615
630
"@{a: 10, b: 1.234}" ) ;
616
631
exact_test ( & ( ~P { a : 10 , b : 1.234 } ) ,
617
632
"~{a: 10, b: 1.234}" ) ;
618
- exact_test ( & ( 10_u8 , ~"hello") ,
619
- "(10 , ~\" hello\" )" ) ;
620
- exact_test ( & ( 10_u16 , ~"hello") ,
621
- "(10 , ~\" hello\" )" ) ;
622
- exact_test ( & ( 10_u32 , ~"hello") ,
623
- "(10 , ~\" hello\" )" ) ;
624
- exact_test ( & ( 10_u64 , ~"hello") ,
625
- "(10 , ~\" hello\" )" ) ;
633
+ exact_test ( & ( 10u8 , ~"hello") ,
634
+ "(10u8 , ~\" hello\" )" ) ;
635
+ exact_test ( & ( 10u16 , ~"hello") ,
636
+ "(10u16 , ~\" hello\" )" ) ;
637
+ exact_test ( & ( 10u32 , ~"hello") ,
638
+ "(10u32 , ~\" hello\" )" ) ;
639
+ exact_test ( & ( 10u64 , ~"hello") ,
640
+ "(10u64 , ~\" hello\" )" ) ;
626
641
627
642
struct Foo ;
628
643
exact_test ( & ( ~[ Foo , Foo , Foo ] ) , "~[{}, {}, {}]" ) ;
0 commit comments