@@ -539,12 +539,8 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for [T] {
539
539
540
540
impl < S : Encoder , T : Encodable < S > > Encodable < S > for Vec < T > {
541
541
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
542
- s. emit_seq ( self . len ( ) , |s| {
543
- for ( i, e) in self . iter ( ) . enumerate ( ) {
544
- s. emit_seq_elt ( i, |s| e. encode ( s) ) ?
545
- }
546
- Ok ( ( ) )
547
- } )
542
+ let slice: & [ T ] = self ;
543
+ slice. encode ( s)
548
544
}
549
545
}
550
546
@@ -560,22 +556,18 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Vec<T> {
560
556
}
561
557
}
562
558
563
- impl < S : Encoder > Encodable < S > for [ u8 ; 20 ] {
559
+ impl < S : Encoder , T : Encodable < S > , const N : usize > Encodable < S > for [ T ; N ] {
564
560
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
565
- s. emit_seq ( self . len ( ) , |s| {
566
- for ( i, e) in self . iter ( ) . enumerate ( ) {
567
- s. emit_seq_elt ( i, |s| e. encode ( s) ) ?
568
- }
569
- Ok ( ( ) )
570
- } )
561
+ let slice: & [ T ] = self ;
562
+ slice. encode ( s)
571
563
}
572
564
}
573
565
574
- impl < D : Decoder > Decodable < D > for [ u8 ; 20 ] {
575
- fn decode ( d : & mut D ) -> Result < [ u8 ; 20 ] , D :: Error > {
566
+ impl < D : Decoder , const N : usize > Decodable < D > for [ u8 ; N ] {
567
+ fn decode ( d : & mut D ) -> Result < [ u8 ; N ] , D :: Error > {
576
568
d. read_seq ( |d, len| {
577
- assert ! ( len == 20 ) ;
578
- let mut v = [ 0u8 ; 20 ] ;
569
+ assert ! ( len == N ) ;
570
+ let mut v = [ 0u8 ; N ] ;
579
571
for i in 0 ..len {
580
572
v[ i] = d. read_seq_elt ( i, |d| Decodable :: decode ( d) ) ?;
581
573
}
@@ -589,12 +581,8 @@ where
589
581
[ T ] : ToOwned < Owned = Vec < T > > ,
590
582
{
591
583
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
592
- s. emit_seq ( self . len ( ) , |s| {
593
- for ( i, e) in self . iter ( ) . enumerate ( ) {
594
- s. emit_seq_elt ( i, |s| e. encode ( s) ) ?
595
- }
596
- Ok ( ( ) )
597
- } )
584
+ let slice: & [ T ] = self ;
585
+ slice. encode ( s)
598
586
}
599
587
}
600
588
0 commit comments