@@ -44,6 +44,7 @@ pub trait Encoder {
4444 f ( self )
4545 }
4646
47+ #[ inline]
4748 fn emit_enum_variant < F > (
4849 & mut self ,
4950 _v_name : & str ,
@@ -113,6 +114,7 @@ pub trait Encoder {
113114 }
114115
115116 // Specialized types:
117+ #[ inline]
116118 fn emit_option < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
117119 where
118120 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
@@ -125,13 +127,15 @@ pub trait Encoder {
125127 self . emit_enum_variant ( "None" , 0 , 0 , |_| Ok ( ( ) ) )
126128 }
127129
130+ #[ inline]
128131 fn emit_option_some < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
129132 where
130133 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
131134 {
132135 self . emit_enum_variant ( "Some" , 1 , 1 , f)
133136 }
134137
138+ #[ inline]
135139 fn emit_seq < F > ( & mut self , len : usize , f : F ) -> Result < ( ) , Self :: Error >
136140 where
137141 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
@@ -148,6 +152,7 @@ pub trait Encoder {
148152 f ( self )
149153 }
150154
155+ #[ inline]
151156 fn emit_map < F > ( & mut self , len : usize , f : F ) -> Result < ( ) , Self :: Error >
152157 where
153158 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
@@ -235,12 +240,14 @@ macro_rules! direct_serialize_impls {
235240 ( $( $ty: ident $emit_method: ident $read_method: ident) ,* ) => {
236241 $(
237242 impl <S : Encoder > Encodable <S > for $ty {
243+ #[ inline]
238244 fn encode( & self , s: & mut S ) -> Result <( ) , S :: Error > {
239245 s. $emit_method( * self )
240246 }
241247 }
242248
243249 impl <D : Decoder > Decodable <D > for $ty {
250+ #[ inline]
244251 fn decode( d: & mut D ) -> $ty {
245252 d. $read_method( )
246253 }
@@ -281,77 +288,90 @@ impl<D: Decoder> Decodable<D> for ! {
281288}
282289
283290impl < S : Encoder > Encodable < S > for :: std:: num:: NonZeroU32 {
291+ #[ inline]
284292 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
285293 s. emit_u32 ( self . get ( ) )
286294 }
287295}
288296
289297impl < D : Decoder > Decodable < D > for :: std:: num:: NonZeroU32 {
298+ #[ inline]
290299 fn decode ( d : & mut D ) -> Self {
291300 :: std:: num:: NonZeroU32 :: new ( d. read_u32 ( ) ) . unwrap ( )
292301 }
293302}
294303
295304impl < S : Encoder > Encodable < S > for str {
305+ #[ inline]
296306 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
297307 s. emit_str ( self )
298308 }
299309}
300310
301311impl < S : Encoder > Encodable < S > for & str {
312+ #[ inline]
302313 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
303314 s. emit_str ( self )
304315 }
305316}
306317
307318impl < S : Encoder > Encodable < S > for String {
319+ #[ inline]
308320 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
309321 s. emit_str ( & self [ ..] )
310322 }
311323}
312324
313325impl < D : Decoder > Decodable < D > for String {
326+ #[ inline]
314327 fn decode ( d : & mut D ) -> String {
315328 d. read_str ( ) . to_owned ( )
316329 }
317330}
318331
319332impl < S : Encoder > Encodable < S > for ( ) {
333+ #[ inline]
320334 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
321335 s. emit_unit ( )
322336 }
323337}
324338
325339impl < D : Decoder > Decodable < D > for ( ) {
340+ #[ inline]
326341 fn decode ( _: & mut D ) -> ( ) { }
327342}
328343
329344impl < S : Encoder , T > Encodable < S > for PhantomData < T > {
345+ #[ inline]
330346 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
331347 s. emit_unit ( )
332348 }
333349}
334350
335351impl < D : Decoder , T > Decodable < D > for PhantomData < T > {
352+ #[ inline]
336353 fn decode ( _: & mut D ) -> PhantomData < T > {
337354 PhantomData
338355 }
339356}
340357
341358impl < D : Decoder , T : Decodable < D > > Decodable < D > for Box < [ T ] > {
359+ #[ inline]
342360 fn decode ( d : & mut D ) -> Box < [ T ] > {
343361 let v: Vec < T > = Decodable :: decode ( d) ;
344362 v. into_boxed_slice ( )
345363 }
346364}
347365
348366impl < S : Encoder , T : Encodable < S > > Encodable < S > for Rc < T > {
367+ #[ inline]
349368 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
350369 ( * * self ) . encode ( s)
351370 }
352371}
353372
354373impl < D : Decoder , T : Decodable < D > > Decodable < D > for Rc < T > {
374+ #[ inline]
355375 fn decode ( d : & mut D ) -> Rc < T > {
356376 Rc :: new ( Decodable :: decode ( d) )
357377 }
@@ -369,6 +389,7 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for [T] {
369389}
370390
371391impl < S : Encoder , T : Encodable < S > > Encodable < S > for Vec < T > {
392+ #[ inline]
372393 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
373394 let slice: & [ T ] = self ;
374395 slice. encode ( s)
@@ -393,13 +414,15 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Vec<T> {
393414}
394415
395416impl < S : Encoder , T : Encodable < S > , const N : usize > Encodable < S > for [ T ; N ] {
417+ #[ inline]
396418 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
397419 let slice: & [ T ] = self ;
398420 slice. encode ( s)
399421 }
400422}
401423
402424impl < D : Decoder , const N : usize > Decodable < D > for [ u8 ; N ] {
425+ #[ inline]
403426 fn decode ( d : & mut D ) -> [ u8 ; N ] {
404427 let len = d. read_usize ( ) ;
405428 assert ! ( len == N ) ;
@@ -415,6 +438,7 @@ impl<'a, S: Encoder, T: Encodable<S>> Encodable<S> for Cow<'a, [T]>
415438where
416439 [ T ] : ToOwned < Owned = Vec < T > > ,
417440{
441+ #[ inline]
418442 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
419443 let slice: & [ T ] = self ;
420444 slice. encode ( s)
@@ -425,13 +449,15 @@ impl<D: Decoder, T: Decodable<D> + ToOwned> Decodable<D> for Cow<'static, [T]>
425449where
426450 [ T ] : ToOwned < Owned = Vec < T > > ,
427451{
452+ #[ inline]
428453 fn decode ( d : & mut D ) -> Cow < ' static , [ T ] > {
429454 let v: Vec < T > = Decodable :: decode ( d) ;
430455 Cow :: Owned ( v)
431456 }
432457}
433458
434459impl < S : Encoder , T : Encodable < S > > Encodable < S > for Option < T > {
460+ #[ inline]
435461 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
436462 s. emit_option ( |s| match * self {
437463 None => s. emit_option_none ( ) ,
@@ -441,6 +467,7 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for Option<T> {
441467}
442468
443469impl < D : Decoder , T : Decodable < D > > Decodable < D > for Option < T > {
470+ #[ inline]
444471 fn decode ( d : & mut D ) -> Option < T > {
445472 match d. read_usize ( ) {
446473 0 => None ,
@@ -451,6 +478,7 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Option<T> {
451478}
452479
453480impl < S : Encoder , T1 : Encodable < S > , T2 : Encodable < S > > Encodable < S > for Result < T1 , T2 > {
481+ #[ inline]
454482 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
455483 s. emit_enum ( |s| match * self {
456484 Ok ( ref v) => {
@@ -464,6 +492,7 @@ impl<S: Encoder, T1: Encodable<S>, T2: Encodable<S>> Encodable<S> for Result<T1,
464492}
465493
466494impl < D : Decoder , T1 : Decodable < D > , T2 : Decodable < D > > Decodable < D > for Result < T1 , T2 > {
495+ #[ inline]
467496 fn decode ( d : & mut D ) -> Result < T1 , T2 > {
468497 match d. read_usize ( ) {
469498 0 => Ok ( T1 :: decode ( d) ) ,
@@ -494,12 +523,14 @@ macro_rules! tuple {
494523 ( ) => ( ) ;
495524 ( $( $name: ident, ) + ) => (
496525 impl <D : Decoder , $( $name: Decodable <D >) ,+> Decodable <D > for ( $( $name, ) +) {
526+ #[ inline]
497527 fn decode( d: & mut D ) -> ( $( $name, ) +) {
498528 ( $( { let element: $name = Decodable :: decode( d) ; element } , ) +)
499529 }
500530 }
501531 impl <S : Encoder , $( $name: Encodable <S >) ,+> Encodable <S > for ( $( $name, ) +) {
502532 #[ allow( non_snake_case) ]
533+ #[ inline]
503534 fn encode( & self , s: & mut S ) -> Result <( ) , S :: Error > {
504535 let ( $( ref $name, ) +) = * self ;
505536 let len: usize = count!( $( $name) +) ;
@@ -517,31 +548,36 @@ macro_rules! tuple {
517548tuple ! { T0 , T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , }
518549
519550impl < S : Encoder > Encodable < S > for path:: Path {
551+ #[ inline]
520552 fn encode ( & self , e : & mut S ) -> Result < ( ) , S :: Error > {
521553 self . to_str ( ) . unwrap ( ) . encode ( e)
522554 }
523555}
524556
525557impl < S : Encoder > Encodable < S > for path:: PathBuf {
558+ #[ inline]
526559 fn encode ( & self , e : & mut S ) -> Result < ( ) , S :: Error > {
527560 path:: Path :: encode ( self , e)
528561 }
529562}
530563
531564impl < D : Decoder > Decodable < D > for path:: PathBuf {
565+ #[ inline]
532566 fn decode ( d : & mut D ) -> path:: PathBuf {
533567 let bytes: String = Decodable :: decode ( d) ;
534568 path:: PathBuf :: from ( bytes)
535569 }
536570}
537571
538572impl < S : Encoder , T : Encodable < S > + Copy > Encodable < S > for Cell < T > {
573+ #[ inline]
539574 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
540575 self . get ( ) . encode ( s)
541576 }
542577}
543578
544579impl < D : Decoder , T : Decodable < D > + Copy > Decodable < D > for Cell < T > {
580+ #[ inline]
545581 fn decode ( d : & mut D ) -> Cell < T > {
546582 Cell :: new ( Decodable :: decode ( d) )
547583 }
@@ -553,35 +589,41 @@ impl<D: Decoder, T: Decodable<D> + Copy> Decodable<D> for Cell<T> {
553589// from `encode` when `try_borrow` returns `None`.
554590
555591impl < S : Encoder , T : Encodable < S > > Encodable < S > for RefCell < T > {
592+ #[ inline]
556593 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
557594 self . borrow ( ) . encode ( s)
558595 }
559596}
560597
561598impl < D : Decoder , T : Decodable < D > > Decodable < D > for RefCell < T > {
599+ #[ inline]
562600 fn decode ( d : & mut D ) -> RefCell < T > {
563601 RefCell :: new ( Decodable :: decode ( d) )
564602 }
565603}
566604
567605impl < S : Encoder , T : Encodable < S > > Encodable < S > for Arc < T > {
606+ #[ inline]
568607 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
569608 ( * * self ) . encode ( s)
570609 }
571610}
572611
573612impl < D : Decoder , T : Decodable < D > > Decodable < D > for Arc < T > {
613+ #[ inline]
574614 fn decode ( d : & mut D ) -> Arc < T > {
575615 Arc :: new ( Decodable :: decode ( d) )
576616 }
577617}
578618
579619impl < S : Encoder , T : ?Sized + Encodable < S > > Encodable < S > for Box < T > {
620+ #[ inline]
580621 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
581622 ( * * self ) . encode ( s)
582623 }
583624}
584625impl < D : Decoder , T : Decodable < D > > Decodable < D > for Box < T > {
626+ #[ inline]
585627 fn decode ( d : & mut D ) -> Box < T > {
586628 Box :: new ( Decodable :: decode ( d) )
587629 }
0 commit comments