@@ -46,58 +46,67 @@ pub trait Encoder {
46
46
47
47
// Compound types:
48
48
fn emit_enum < F > ( & mut self , _name : & str , f : F ) -> Result < ( ) , Self :: Error >
49
- where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > { f ( self ) }
50
-
51
- fn emit_enum_variant < F > ( & mut self , _v_name : & str ,
52
- v_id : usize ,
53
- _len : usize ,
54
- f : F ) -> Result < ( ) , Self :: Error >
55
49
where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
50
+ {
51
+ f ( self )
52
+ }
53
+
54
+ fn emit_enum_variant < F > ( & mut self , _v_name : & str , v_id : usize , _len : usize , f : F )
55
+ -> Result < ( ) , Self :: Error > where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
56
56
{
57
57
self . emit_usize ( v_id) ?;
58
58
f ( self )
59
59
}
60
- fn emit_enum_variant_arg < F > ( & mut self , _a_idx : usize , f : F )
61
- -> Result < ( ) , Self :: Error >
62
- where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > { f ( self ) }
63
60
64
- fn emit_enum_struct_variant < F > ( & mut self , v_name : & str ,
65
- v_id : usize ,
66
- len : usize ,
67
- f : F ) -> Result < ( ) , Self :: Error >
61
+ fn emit_enum_variant_arg < F > ( & mut self , _a_idx : usize , f : F ) -> Result < ( ) , Self :: Error >
68
62
where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
63
+ {
64
+ f ( self )
65
+ }
66
+
67
+ fn emit_enum_struct_variant < F > ( & mut self , v_name : & str , v_id : usize , len : usize , f : F )
68
+ -> Result < ( ) , Self :: Error > where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
69
69
{
70
70
self . emit_enum_variant ( v_name, v_id, len, f)
71
71
}
72
- fn emit_enum_struct_variant_field < F > ( & mut self ,
73
- _f_name : & str ,
74
- f_idx : usize ,
75
- f : F ) -> Result < ( ) , Self :: Error >
76
- where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
72
+
73
+ fn emit_enum_struct_variant_field < F > ( & mut self , _f_name : & str , f_idx : usize , f : F )
74
+ -> Result < ( ) , Self :: Error > where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
77
75
{
78
76
self . emit_enum_variant_arg ( f_idx, f)
79
77
}
80
78
81
- fn emit_struct < F > ( & mut self , _name : & str , _len : usize , f : F )
82
- -> Result < ( ) , Self :: Error >
83
- where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > { f ( self ) }
79
+ fn emit_struct < F > ( & mut self , _name : & str , _len : usize , f : F ) -> Result < ( ) , Self :: Error >
80
+ where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
81
+ {
82
+ f ( self )
83
+ }
84
+
84
85
fn emit_struct_field < F > ( & mut self , _f_name : & str , _f_idx : usize , f : F )
85
- -> Result < ( ) , Self :: Error >
86
- where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > { f ( self ) }
86
+ -> Result < ( ) , Self :: Error > where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
87
+ {
88
+ f ( self )
89
+ }
87
90
88
91
fn emit_tuple < F > ( & mut self , _len : usize , f : F ) -> Result < ( ) , Self :: Error >
89
- where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > { f ( self ) }
92
+ where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
93
+ {
94
+ f ( self )
95
+ }
96
+
90
97
fn emit_tuple_arg < F > ( & mut self , _idx : usize , f : F ) -> Result < ( ) , Self :: Error >
91
- where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > { f ( self ) }
98
+ where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
99
+ {
100
+ f ( self )
101
+ }
92
102
93
- fn emit_tuple_struct < F > ( & mut self , _name : & str , len : usize , f : F )
94
- -> Result < ( ) , Self :: Error >
103
+ fn emit_tuple_struct < F > ( & mut self , _name : & str , len : usize , f : F ) -> Result < ( ) , Self :: Error >
95
104
where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
96
105
{
97
106
self . emit_tuple ( len, f)
98
107
}
99
- fn emit_tuple_struct_arg < F > ( & mut self , f_idx : usize , f : F )
100
- -> Result < ( ) , Self :: Error >
108
+
109
+ fn emit_tuple_struct_arg < F > ( & mut self , f_idx : usize , f : F ) -> Result < ( ) , Self :: Error >
101
110
where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
102
111
{
103
112
self . emit_tuple_arg ( f_idx, f)
@@ -109,13 +118,14 @@ pub trait Encoder {
109
118
{
110
119
self . emit_enum ( "Option" , f)
111
120
}
121
+
112
122
fn emit_option_none ( & mut self ) -> Result < ( ) , Self :: Error > {
113
123
self . emit_enum_variant ( "None" , 0 , 0 , |_| Ok ( ( ) ) )
114
124
}
125
+
115
126
fn emit_option_some < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
116
127
where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
117
128
{
118
-
119
129
self . emit_enum_variant ( "Some" , 1 , 1 , f)
120
130
}
121
131
@@ -125,19 +135,31 @@ pub trait Encoder {
125
135
self . emit_usize ( len) ?;
126
136
f ( self )
127
137
}
138
+
128
139
fn emit_seq_elt < F > ( & mut self , _idx : usize , f : F ) -> Result < ( ) , Self :: Error >
129
- where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > { f ( self ) }
140
+ where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
141
+ {
142
+ f ( self )
143
+ }
130
144
131
145
fn emit_map < F > ( & mut self , len : usize , f : F ) -> Result < ( ) , Self :: Error >
132
146
where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
133
147
{
134
148
self . emit_usize ( len) ?;
135
149
f ( self )
136
150
}
151
+
137
152
fn emit_map_elt_key < F > ( & mut self , _idx : usize , f : F ) -> Result < ( ) , Self :: Error >
138
- where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > { f ( self ) }
153
+ where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
154
+ {
155
+ f ( self )
156
+ }
157
+
139
158
fn emit_map_elt_val < F > ( & mut self , _idx : usize , f : F ) -> Result < ( ) , Self :: Error >
140
- where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > { f ( self ) }
159
+ where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
160
+ {
161
+ f ( self )
162
+ }
141
163
}
142
164
143
165
pub trait Decoder {
@@ -165,59 +187,67 @@ pub trait Decoder {
165
187
166
188
// Compound types:
167
189
fn read_enum < T , F > ( & mut self , _name : & str , f : F ) -> Result < T , Self :: Error >
168
- where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error > { f ( self ) }
190
+ where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
191
+ {
192
+ f ( self )
193
+ }
169
194
170
- fn read_enum_variant < T , F > ( & mut self , _names : & [ & str ] , mut f : F )
171
- -> Result < T , Self :: Error >
195
+ fn read_enum_variant < T , F > ( & mut self , _names : & [ & str ] , mut f : F ) -> Result < T , Self :: Error >
172
196
where F : FnMut ( & mut Self , usize ) -> Result < T , Self :: Error >
173
197
{
174
198
let disr = self . read_usize ( ) ?;
175
199
f ( self , disr)
176
200
}
177
- fn read_enum_variant_arg < T , F > ( & mut self , _a_idx : usize , f : F )
178
- -> Result < T , Self :: Error >
179
- where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error > { f ( self ) }
180
201
181
- fn read_enum_struct_variant < T , F > ( & mut self , names : & [ & str ] , f : F )
182
- -> Result < T , Self :: Error >
202
+ fn read_enum_variant_arg < T , F > ( & mut self , _a_idx : usize , f : F ) -> Result < T , Self :: Error >
203
+ where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
204
+ {
205
+ f ( self )
206
+ }
207
+
208
+ fn read_enum_struct_variant < T , F > ( & mut self , names : & [ & str ] , f : F ) -> Result < T , Self :: Error >
183
209
where F : FnMut ( & mut Self , usize ) -> Result < T , Self :: Error >
184
210
{
185
211
self . read_enum_variant ( names, f)
186
212
}
187
- fn read_enum_struct_variant_field < T , F > ( & mut self ,
188
- _f_name : & str ,
189
- f_idx : usize ,
190
- f : F )
191
- -> Result < T , Self :: Error >
192
- where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
213
+
214
+ fn read_enum_struct_variant_field < T , F > ( & mut self , _f_name : & str , f_idx : usize , f : F )
215
+ -> Result < T , Self :: Error > where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
193
216
{
194
217
self . read_enum_variant_arg ( f_idx, f)
195
218
}
196
219
197
- fn read_struct < T , F > ( & mut self , _s_name : & str , _len : usize , f : F )
198
- -> Result < T , Self :: Error >
199
- where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error > { f ( self ) }
200
- fn read_struct_field < T , F > ( & mut self ,
201
- _f_name : & str ,
202
- _f_idx : usize ,
203
- f : F )
204
- -> Result < T , Self :: Error >
205
- where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error > { f ( self ) }
220
+ fn read_struct < T , F > ( & mut self , _s_name : & str , _len : usize , f : F ) -> Result < T , Self :: Error >
221
+ where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
222
+ {
223
+ f ( self )
224
+ }
225
+
226
+ fn read_struct_field < T , F > ( & mut self , _f_name : & str , _f_idx : usize , f : F )
227
+ -> Result < T , Self :: Error > where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
228
+ {
229
+ f ( self )
230
+ }
206
231
207
232
fn read_tuple < T , F > ( & mut self , _len : usize , f : F ) -> Result < T , Self :: Error >
208
- where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error > { f ( self ) }
209
- fn read_tuple_arg < T , F > ( & mut self , _a_idx : usize , f : F )
210
- -> Result < T , Self :: Error >
211
- where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error > { f ( self ) }
233
+ where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
234
+ {
235
+ f ( self )
236
+ }
237
+
238
+ fn read_tuple_arg < T , F > ( & mut self , _a_idx : usize , f : F ) -> Result < T , Self :: Error >
239
+ where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
240
+ {
241
+ f ( self )
242
+ }
212
243
213
- fn read_tuple_struct < T , F > ( & mut self , _s_name : & str , len : usize , f : F )
214
- -> Result < T , Self :: Error >
244
+ fn read_tuple_struct < T , F > ( & mut self , _s_name : & str , len : usize , f : F ) -> Result < T , Self :: Error >
215
245
where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
216
246
{
217
247
self . read_tuple ( len, f)
218
248
}
219
- fn read_tuple_struct_arg < T , F > ( & mut self , a_idx : usize , f : F )
220
- -> Result < T , Self :: Error >
249
+
250
+ fn read_tuple_struct_arg < T , F > ( & mut self , a_idx : usize , f : F ) -> Result < T , Self :: Error >
221
251
where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
222
252
{
223
253
self . read_tuple_arg ( a_idx, f)
@@ -244,21 +274,31 @@ pub trait Decoder {
244
274
let len = self . read_usize ( ) ?;
245
275
f ( self , len)
246
276
}
277
+
247
278
fn read_seq_elt < T , F > ( & mut self , _idx : usize , f : F ) -> Result < T , Self :: Error >
248
- where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error > { f ( self ) }
279
+ where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
280
+ {
281
+ f ( self )
282
+ }
249
283
250
284
fn read_map < T , F > ( & mut self , f : F ) -> Result < T , Self :: Error >
251
285
where F : FnOnce ( & mut Self , usize ) -> Result < T , Self :: Error >
252
286
{
253
287
let len = self . read_usize ( ) ?;
254
288
f ( self , len)
255
289
}
256
- fn read_map_elt_key < T , F > ( & mut self , _idx : usize , f : F )
257
- -> Result < T , Self :: Error >
258
- where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error > { f ( self ) }
259
- fn read_map_elt_val < T , F > ( & mut self , _idx : usize , f : F )
260
- -> Result < T , Self :: Error >
261
- where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error > { f ( self ) }
290
+
291
+ fn read_map_elt_key < T , F > ( & mut self , _idx : usize , f : F ) -> Result < T , Self :: Error >
292
+ where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
293
+ {
294
+ f ( self )
295
+ }
296
+
297
+ fn read_map_elt_val < T , F > ( & mut self , _idx : usize , f : F ) -> Result < T , Self :: Error >
298
+ where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
299
+ {
300
+ f ( self )
301
+ }
262
302
263
303
// Failure
264
304
fn error ( & mut self , err : & str ) -> Self :: Error ;
@@ -567,9 +607,7 @@ impl<T:Decodable> Decodable for Vec<T> {
567
607
}
568
608
}
569
609
570
- impl < ' a , T : Encodable > Encodable for Cow < ' a , [ T ] >
571
- where [ T ] : ToOwned < Owned = Vec < T > >
572
- {
610
+ impl < ' a , T : Encodable > Encodable for Cow < ' a , [ T ] > where [ T ] : ToOwned < Owned = Vec < T > > {
573
611
fn encode < S : Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
574
612
s. emit_seq ( self . len ( ) , |s| {
575
613
for ( i, e) in self . iter ( ) . enumerate ( ) {
@@ -580,9 +618,7 @@ where [T]: ToOwned<Owned = Vec<T>>
580
618
}
581
619
}
582
620
583
- impl < T : Decodable +ToOwned > Decodable for Cow < ' static , [ T ] >
584
- where [ T ] : ToOwned < Owned = Vec < T > >
585
- {
621
+ impl < T : Decodable +ToOwned > Decodable for Cow < ' static , [ T ] > where [ T ] : ToOwned < Owned = Vec < T > > {
586
622
fn decode < D : Decoder > ( d : & mut D ) -> Result < Cow < ' static , [ T ] > , D :: Error > {
587
623
d. read_seq ( |d, len| {
588
624
let mut v = Vec :: with_capacity ( len) ;
@@ -685,8 +721,7 @@ macro_rules! tuple {
685
721
let len: usize = count_idents!( $( $name, ) * ) ;
686
722
d. read_tuple( len, |d| {
687
723
let mut i = 0 ;
688
- let ret = ( $( d. read_tuple_arg( { i+=1 ; i-1 } ,
689
- |d| -> Result <$name, D :: Error > {
724
+ let ret = ( $( d. read_tuple_arg( { i+=1 ; i-1 } , |d| -> Result <$name, D :: Error > {
690
725
Decodable :: decode( d)
691
726
} ) ?, ) * ) ;
692
727
Ok ( ret)
@@ -778,13 +813,11 @@ pub trait SpecializationError {
778
813
/// `T` is the type being encoded/decoded, and
779
814
/// the arguments are the names of the trait
780
815
/// and method that should've been overridden.
781
- fn not_found < S , T : ?Sized > ( trait_name : & ' static str ,
782
- method_name : & ' static str ) -> Self ;
816
+ fn not_found < S , T : ?Sized > ( trait_name : & ' static str , method_name : & ' static str ) -> Self ;
783
817
}
784
818
785
819
impl < E > SpecializationError for E {
786
- default fn not_found < S , T : ?Sized > ( trait_name : & ' static str ,
787
- method_name : & ' static str ) -> E {
820
+ default fn not_found < S , T : ?Sized > ( trait_name : & ' static str , method_name : & ' static str ) -> E {
788
821
panic ! ( "missing specialization: `<{} as {}<{}>>::{}` not overridden" ,
789
822
unsafe { intrinsics:: type_name:: <S >( ) } ,
790
823
trait_name,
0 commit comments