@@ -46,58 +46,67 @@ pub trait Encoder {
4646
4747 // Compound types:
4848 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 >
5549 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 >
5656 {
5757 self . emit_usize ( v_id) ?;
5858 f ( self )
5959 }
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 ) }
6360
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 >
6862 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 >
6969 {
7070 self . emit_enum_variant ( v_name, v_id, len, f)
7171 }
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 >
7775 {
7876 self . emit_enum_variant_arg ( f_idx, f)
7977 }
8078
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+
8485 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+ }
8790
8891 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+
9097 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+ }
92102
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 >
95104 where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
96105 {
97106 self . emit_tuple ( len, f)
98107 }
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 >
101110 where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
102111 {
103112 self . emit_tuple_arg ( f_idx, f)
@@ -109,13 +118,14 @@ pub trait Encoder {
109118 {
110119 self . emit_enum ( "Option" , f)
111120 }
121+
112122 fn emit_option_none ( & mut self ) -> Result < ( ) , Self :: Error > {
113123 self . emit_enum_variant ( "None" , 0 , 0 , |_| Ok ( ( ) ) )
114124 }
125+
115126 fn emit_option_some < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
116127 where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
117128 {
118-
119129 self . emit_enum_variant ( "Some" , 1 , 1 , f)
120130 }
121131
@@ -125,19 +135,31 @@ pub trait Encoder {
125135 self . emit_usize ( len) ?;
126136 f ( self )
127137 }
138+
128139 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+ }
130144
131145 fn emit_map < F > ( & mut self , len : usize , f : F ) -> Result < ( ) , Self :: Error >
132146 where F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error >
133147 {
134148 self . emit_usize ( len) ?;
135149 f ( self )
136150 }
151+
137152 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+
139158 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+ }
141163}
142164
143165pub trait Decoder {
@@ -165,59 +187,67 @@ pub trait Decoder {
165187
166188 // Compound types:
167189 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+ }
169194
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 >
172196 where F : FnMut ( & mut Self , usize ) -> Result < T , Self :: Error >
173197 {
174198 let disr = self . read_usize ( ) ?;
175199 f ( self , disr)
176200 }
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 ) }
180201
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 >
183209 where F : FnMut ( & mut Self , usize ) -> Result < T , Self :: Error >
184210 {
185211 self . read_enum_variant ( names, f)
186212 }
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 >
193216 {
194217 self . read_enum_variant_arg ( f_idx, f)
195218 }
196219
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+ }
206231
207232 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+ }
212243
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 >
215245 where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
216246 {
217247 self . read_tuple ( len, f)
218248 }
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 >
221251 where F : FnOnce ( & mut Self ) -> Result < T , Self :: Error >
222252 {
223253 self . read_tuple_arg ( a_idx, f)
@@ -244,21 +274,31 @@ pub trait Decoder {
244274 let len = self . read_usize ( ) ?;
245275 f ( self , len)
246276 }
277+
247278 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+ }
249283
250284 fn read_map < T , F > ( & mut self , f : F ) -> Result < T , Self :: Error >
251285 where F : FnOnce ( & mut Self , usize ) -> Result < T , Self :: Error >
252286 {
253287 let len = self . read_usize ( ) ?;
254288 f ( self , len)
255289 }
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+ }
262302
263303 // Failure
264304 fn error ( & mut self , err : & str ) -> Self :: Error ;
@@ -567,9 +607,7 @@ impl<T:Decodable> Decodable for Vec<T> {
567607 }
568608}
569609
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 > > {
573611 fn encode < S : Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
574612 s. emit_seq ( self . len ( ) , |s| {
575613 for ( i, e) in self . iter ( ) . enumerate ( ) {
@@ -580,9 +618,7 @@ where [T]: ToOwned<Owned = Vec<T>>
580618 }
581619}
582620
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 > > {
586622 fn decode < D : Decoder > ( d : & mut D ) -> Result < Cow < ' static , [ T ] > , D :: Error > {
587623 d. read_seq ( |d, len| {
588624 let mut v = Vec :: with_capacity ( len) ;
@@ -685,8 +721,7 @@ macro_rules! tuple {
685721 let len: usize = count_idents!( $( $name, ) * ) ;
686722 d. read_tuple( len, |d| {
687723 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 > {
690725 Decodable :: decode( d)
691726 } ) ?, ) * ) ;
692727 Ok ( ret)
@@ -778,13 +813,11 @@ pub trait SpecializationError {
778813 /// `T` is the type being encoded/decoded, and
779814 /// the arguments are the names of the trait
780815 /// 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 ;
783817}
784818
785819impl < 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 {
788821 panic ! ( "missing specialization: `<{} as {}<{}>>::{}` not overridden" ,
789822 unsafe { intrinsics:: type_name:: <S >( ) } ,
790823 trait_name,
0 commit comments