1- use std:: { fmt, marker:: PhantomData } ;
1+ use std:: { any :: type_name , fmt, marker:: PhantomData } ;
22
33use bytes:: { Buf , Bytes } ;
44use serde:: {
55 de:: {
6- self , value:: SeqDeserializer , DeserializeSeed , EnumAccess , IntoDeserializer as _ ,
7- MapAccess , SeqAccess , VariantAccess , Visitor ,
6+ self , value:: SeqDeserializer , DeserializeSeed , EnumAccess , IgnoredAny ,
7+ IntoDeserializer as _ , MapAccess , SeqAccess , VariantAccess , Visitor ,
88 } ,
99 forward_to_deserialize_any,
1010} ;
@@ -207,8 +207,10 @@ impl<'de> Deserializer<'de> {
207207 let start = full_bytes. as_ptr ( ) ;
208208 let end = self . bytes . as_ptr ( ) ;
209209
210+ // SAFETY: both pointers are from the same allocation and end is >= start
210211 let len = unsafe { end. offset_from ( start) } ;
211212 full_bytes. truncate ( len. unsigned_abs ( ) ) ;
213+
212214 Ok ( full_bytes)
213215 }
214216
@@ -358,20 +360,25 @@ impl<'a> ItemsParser<'a> {
358360 self . excess = excess;
359361 self
360362 }
363+
364+ fn drain ( & mut self ) -> Result < ( ) , Error > {
365+ let bytes = self . bytes . get ( ) ;
366+ for _ in 0 ..( self . len + self . excess ) {
367+ Deserializer { bytes } . skip_next_item ( ) ?;
368+ }
369+ Ok ( ( ) )
370+ }
361371}
362372
363- impl < ' a , ' de > SeqAccess < ' de > for ItemsParser < ' a > {
373+ impl < ' de > SeqAccess < ' de > for ItemsParser < ' _ > {
364374 type Error = Error ;
365375
366376 fn next_element_seed < T > ( & mut self , seed : T ) -> Result < Option < T :: Value > , Self :: Error >
367377 where
368378 T : DeserializeSeed < ' de > ,
369379 {
370380 if self . len == 0 {
371- let bytes = self . bytes . get ( ) ;
372- for _ in 0 ..self . excess {
373- Deserializer { bytes } . skip_next_item ( ) ?;
374- }
381+ self . drain ( ) ?;
375382 return Ok ( None ) ;
376383 }
377384 self . len -= 1 ;
@@ -388,7 +395,7 @@ impl<'a, 'de> SeqAccess<'de> for ItemsParser<'a> {
388395 }
389396}
390397
391- impl < ' a , ' de > MapAccess < ' de > for ItemsParser < ' a > {
398+ impl < ' de > MapAccess < ' de > for ItemsParser < ' _ > {
392399 type Error = Error ;
393400
394401 fn next_key_seed < K > ( & mut self , seed : K ) -> Result < Option < K :: Value > , Self :: Error >
@@ -420,7 +427,7 @@ impl<'a, 'de> MapAccess<'de> for ItemsParser<'a> {
420427 }
421428}
422429
423- impl < ' a , ' de > VariantAccess < ' de > for ItemsParser < ' a > {
430+ impl < ' de > VariantAccess < ' de > for ItemsParser < ' _ > {
424431 type Error = Error ;
425432
426433 fn unit_variant ( mut self ) -> Result < ( ) , Self :: Error > {
@@ -431,6 +438,11 @@ impl<'a, 'de> VariantAccess<'de> for ItemsParser<'a> {
431438 where
432439 T : DeserializeSeed < ' de > ,
433440 {
441+ if type_name :: < T > ( ) == type_name :: < PhantomData < IgnoredAny > > ( ) {
442+ self . drain ( ) ?;
443+ return seed. deserialize ( ( ) . into_deserializer ( ) ) ;
444+ }
445+
434446 self . next_value_seed ( seed)
435447 }
436448
@@ -498,14 +510,14 @@ struct SharedBytes<'a> {
498510}
499511
500512#[ cfg( all( test, debug_assertions) ) ]
501- impl < ' a > fmt:: Debug for SharedBytes < ' a > {
513+ impl fmt:: Debug for SharedBytes < ' _ > {
502514 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
503515 crate :: packstream:: Dbg ( unsafe { & * self . bytes } ) . fmt ( f)
504516 }
505517}
506518
507519#[ cfg( not( all( test, debug_assertions) ) ) ]
508- impl < ' a > fmt:: Debug for SharedBytes < ' a > {
520+ impl fmt:: Debug for SharedBytes < ' _ > {
509521 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
510522 f. debug_struct ( "SharedBytes" ) . finish_non_exhaustive ( )
511523 }
0 commit comments