@@ -44,6 +44,7 @@ pub trait Encoder {
44
44
f ( self )
45
45
}
46
46
47
+ #[ inline]
47
48
fn emit_enum_variant < F > (
48
49
& mut self ,
49
50
_v_name : & str ,
@@ -113,6 +114,7 @@ pub trait Encoder {
113
114
}
114
115
115
116
// Specialized types:
117
+ #[ inline]
116
118
fn emit_option < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
117
119
where
118
120
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
@@ -125,13 +127,15 @@ pub trait Encoder {
125
127
self . emit_enum_variant ( "None" , 0 , 0 , |_| Ok ( ( ) ) )
126
128
}
127
129
130
+ #[ inline]
128
131
fn emit_option_some < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
129
132
where
130
133
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
131
134
{
132
135
self . emit_enum_variant ( "Some" , 1 , 1 , f)
133
136
}
134
137
138
+ #[ inline]
135
139
fn emit_seq < F > ( & mut self , len : usize , f : F ) -> Result < ( ) , Self :: Error >
136
140
where
137
141
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
@@ -148,6 +152,7 @@ pub trait Encoder {
148
152
f ( self )
149
153
}
150
154
155
+ #[ inline]
151
156
fn emit_map < F > ( & mut self , len : usize , f : F ) -> Result < ( ) , Self :: Error >
152
157
where
153
158
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
@@ -235,12 +240,14 @@ macro_rules! direct_serialize_impls {
235
240
( $( $ty: ident $emit_method: ident $read_method: ident) ,* ) => {
236
241
$(
237
242
impl <S : Encoder > Encodable <S > for $ty {
243
+ #[ inline]
238
244
fn encode( & self , s: & mut S ) -> Result <( ) , S :: Error > {
239
245
s. $emit_method( * self )
240
246
}
241
247
}
242
248
243
249
impl <D : Decoder > Decodable <D > for $ty {
250
+ #[ inline]
244
251
fn decode( d: & mut D ) -> $ty {
245
252
d. $read_method( )
246
253
}
@@ -281,77 +288,90 @@ impl<D: Decoder> Decodable<D> for ! {
281
288
}
282
289
283
290
impl < S : Encoder > Encodable < S > for :: std:: num:: NonZeroU32 {
291
+ #[ inline]
284
292
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
285
293
s. emit_u32 ( self . get ( ) )
286
294
}
287
295
}
288
296
289
297
impl < D : Decoder > Decodable < D > for :: std:: num:: NonZeroU32 {
298
+ #[ inline]
290
299
fn decode ( d : & mut D ) -> Self {
291
300
:: std:: num:: NonZeroU32 :: new ( d. read_u32 ( ) ) . unwrap ( )
292
301
}
293
302
}
294
303
295
304
impl < S : Encoder > Encodable < S > for str {
305
+ #[ inline]
296
306
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
297
307
s. emit_str ( self )
298
308
}
299
309
}
300
310
301
311
impl < S : Encoder > Encodable < S > for & str {
312
+ #[ inline]
302
313
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
303
314
s. emit_str ( self )
304
315
}
305
316
}
306
317
307
318
impl < S : Encoder > Encodable < S > for String {
319
+ #[ inline]
308
320
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
309
321
s. emit_str ( & self [ ..] )
310
322
}
311
323
}
312
324
313
325
impl < D : Decoder > Decodable < D > for String {
326
+ #[ inline]
314
327
fn decode ( d : & mut D ) -> String {
315
328
d. read_str ( ) . to_owned ( )
316
329
}
317
330
}
318
331
319
332
impl < S : Encoder > Encodable < S > for ( ) {
333
+ #[ inline]
320
334
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
321
335
s. emit_unit ( )
322
336
}
323
337
}
324
338
325
339
impl < D : Decoder > Decodable < D > for ( ) {
340
+ #[ inline]
326
341
fn decode ( _: & mut D ) -> ( ) { }
327
342
}
328
343
329
344
impl < S : Encoder , T > Encodable < S > for PhantomData < T > {
345
+ #[ inline]
330
346
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
331
347
s. emit_unit ( )
332
348
}
333
349
}
334
350
335
351
impl < D : Decoder , T > Decodable < D > for PhantomData < T > {
352
+ #[ inline]
336
353
fn decode ( _: & mut D ) -> PhantomData < T > {
337
354
PhantomData
338
355
}
339
356
}
340
357
341
358
impl < D : Decoder , T : Decodable < D > > Decodable < D > for Box < [ T ] > {
359
+ #[ inline]
342
360
fn decode ( d : & mut D ) -> Box < [ T ] > {
343
361
let v: Vec < T > = Decodable :: decode ( d) ;
344
362
v. into_boxed_slice ( )
345
363
}
346
364
}
347
365
348
366
impl < S : Encoder , T : Encodable < S > > Encodable < S > for Rc < T > {
367
+ #[ inline]
349
368
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
350
369
( * * self ) . encode ( s)
351
370
}
352
371
}
353
372
354
373
impl < D : Decoder , T : Decodable < D > > Decodable < D > for Rc < T > {
374
+ #[ inline]
355
375
fn decode ( d : & mut D ) -> Rc < T > {
356
376
Rc :: new ( Decodable :: decode ( d) )
357
377
}
@@ -369,6 +389,7 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for [T] {
369
389
}
370
390
371
391
impl < S : Encoder , T : Encodable < S > > Encodable < S > for Vec < T > {
392
+ #[ inline]
372
393
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
373
394
let slice: & [ T ] = self ;
374
395
slice. encode ( s)
@@ -393,13 +414,15 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Vec<T> {
393
414
}
394
415
395
416
impl < S : Encoder , T : Encodable < S > , const N : usize > Encodable < S > for [ T ; N ] {
417
+ #[ inline]
396
418
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
397
419
let slice: & [ T ] = self ;
398
420
slice. encode ( s)
399
421
}
400
422
}
401
423
402
424
impl < D : Decoder , const N : usize > Decodable < D > for [ u8 ; N ] {
425
+ #[ inline]
403
426
fn decode ( d : & mut D ) -> [ u8 ; N ] {
404
427
let len = d. read_usize ( ) ;
405
428
assert ! ( len == N ) ;
@@ -415,6 +438,7 @@ impl<'a, S: Encoder, T: Encodable<S>> Encodable<S> for Cow<'a, [T]>
415
438
where
416
439
[ T ] : ToOwned < Owned = Vec < T > > ,
417
440
{
441
+ #[ inline]
418
442
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
419
443
let slice: & [ T ] = self ;
420
444
slice. encode ( s)
@@ -425,13 +449,15 @@ impl<D: Decoder, T: Decodable<D> + ToOwned> Decodable<D> for Cow<'static, [T]>
425
449
where
426
450
[ T ] : ToOwned < Owned = Vec < T > > ,
427
451
{
452
+ #[ inline]
428
453
fn decode ( d : & mut D ) -> Cow < ' static , [ T ] > {
429
454
let v: Vec < T > = Decodable :: decode ( d) ;
430
455
Cow :: Owned ( v)
431
456
}
432
457
}
433
458
434
459
impl < S : Encoder , T : Encodable < S > > Encodable < S > for Option < T > {
460
+ #[ inline]
435
461
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
436
462
s. emit_option ( |s| match * self {
437
463
None => s. emit_option_none ( ) ,
@@ -441,6 +467,7 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for Option<T> {
441
467
}
442
468
443
469
impl < D : Decoder , T : Decodable < D > > Decodable < D > for Option < T > {
470
+ #[ inline]
444
471
fn decode ( d : & mut D ) -> Option < T > {
445
472
match d. read_usize ( ) {
446
473
0 => None ,
@@ -451,6 +478,7 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Option<T> {
451
478
}
452
479
453
480
impl < S : Encoder , T1 : Encodable < S > , T2 : Encodable < S > > Encodable < S > for Result < T1 , T2 > {
481
+ #[ inline]
454
482
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
455
483
s. emit_enum ( |s| match * self {
456
484
Ok ( ref v) => {
@@ -464,6 +492,7 @@ impl<S: Encoder, T1: Encodable<S>, T2: Encodable<S>> Encodable<S> for Result<T1,
464
492
}
465
493
466
494
impl < D : Decoder , T1 : Decodable < D > , T2 : Decodable < D > > Decodable < D > for Result < T1 , T2 > {
495
+ #[ inline]
467
496
fn decode ( d : & mut D ) -> Result < T1 , T2 > {
468
497
match d. read_usize ( ) {
469
498
0 => Ok ( T1 :: decode ( d) ) ,
@@ -494,12 +523,14 @@ macro_rules! tuple {
494
523
( ) => ( ) ;
495
524
( $( $name: ident, ) + ) => (
496
525
impl <D : Decoder , $( $name: Decodable <D >) ,+> Decodable <D > for ( $( $name, ) +) {
526
+ #[ inline]
497
527
fn decode( d: & mut D ) -> ( $( $name, ) +) {
498
528
( $( { let element: $name = Decodable :: decode( d) ; element } , ) +)
499
529
}
500
530
}
501
531
impl <S : Encoder , $( $name: Encodable <S >) ,+> Encodable <S > for ( $( $name, ) +) {
502
532
#[ allow( non_snake_case) ]
533
+ #[ inline]
503
534
fn encode( & self , s: & mut S ) -> Result <( ) , S :: Error > {
504
535
let ( $( ref $name, ) +) = * self ;
505
536
let len: usize = count!( $( $name) +) ;
@@ -517,31 +548,36 @@ macro_rules! tuple {
517
548
tuple ! { T0 , T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , }
518
549
519
550
impl < S : Encoder > Encodable < S > for path:: Path {
551
+ #[ inline]
520
552
fn encode ( & self , e : & mut S ) -> Result < ( ) , S :: Error > {
521
553
self . to_str ( ) . unwrap ( ) . encode ( e)
522
554
}
523
555
}
524
556
525
557
impl < S : Encoder > Encodable < S > for path:: PathBuf {
558
+ #[ inline]
526
559
fn encode ( & self , e : & mut S ) -> Result < ( ) , S :: Error > {
527
560
path:: Path :: encode ( self , e)
528
561
}
529
562
}
530
563
531
564
impl < D : Decoder > Decodable < D > for path:: PathBuf {
565
+ #[ inline]
532
566
fn decode ( d : & mut D ) -> path:: PathBuf {
533
567
let bytes: String = Decodable :: decode ( d) ;
534
568
path:: PathBuf :: from ( bytes)
535
569
}
536
570
}
537
571
538
572
impl < S : Encoder , T : Encodable < S > + Copy > Encodable < S > for Cell < T > {
573
+ #[ inline]
539
574
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
540
575
self . get ( ) . encode ( s)
541
576
}
542
577
}
543
578
544
579
impl < D : Decoder , T : Decodable < D > + Copy > Decodable < D > for Cell < T > {
580
+ #[ inline]
545
581
fn decode ( d : & mut D ) -> Cell < T > {
546
582
Cell :: new ( Decodable :: decode ( d) )
547
583
}
@@ -553,35 +589,41 @@ impl<D: Decoder, T: Decodable<D> + Copy> Decodable<D> for Cell<T> {
553
589
// from `encode` when `try_borrow` returns `None`.
554
590
555
591
impl < S : Encoder , T : Encodable < S > > Encodable < S > for RefCell < T > {
592
+ #[ inline]
556
593
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
557
594
self . borrow ( ) . encode ( s)
558
595
}
559
596
}
560
597
561
598
impl < D : Decoder , T : Decodable < D > > Decodable < D > for RefCell < T > {
599
+ #[ inline]
562
600
fn decode ( d : & mut D ) -> RefCell < T > {
563
601
RefCell :: new ( Decodable :: decode ( d) )
564
602
}
565
603
}
566
604
567
605
impl < S : Encoder , T : Encodable < S > > Encodable < S > for Arc < T > {
606
+ #[ inline]
568
607
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
569
608
( * * self ) . encode ( s)
570
609
}
571
610
}
572
611
573
612
impl < D : Decoder , T : Decodable < D > > Decodable < D > for Arc < T > {
613
+ #[ inline]
574
614
fn decode ( d : & mut D ) -> Arc < T > {
575
615
Arc :: new ( Decodable :: decode ( d) )
576
616
}
577
617
}
578
618
579
619
impl < S : Encoder , T : ?Sized + Encodable < S > > Encodable < S > for Box < T > {
620
+ #[ inline]
580
621
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
581
622
( * * self ) . encode ( s)
582
623
}
583
624
}
584
625
impl < D : Decoder , T : Decodable < D > > Decodable < D > for Box < T > {
626
+ #[ inline]
585
627
fn decode ( d : & mut D ) -> Box < T > {
586
628
Box :: new ( Decodable :: decode ( d) )
587
629
}
0 commit comments