@@ -66,7 +66,7 @@ impl<'de> Deserializer<'de> {
6666 . iter ( )
6767 . position ( |& b| !b. is_ascii_digit ( ) )
6868 . ok_or ( Error :: ExpectedLength ) ?;
69- let length_str = String :: from_utf8 ( self . input [ ..first_non_numeric] . to_vec ( ) )
69+ let length_str = str :: from_utf8 ( & self . input [ ..first_non_numeric] )
7070 . map_err ( |_| Error :: ExpectedLength ) ?;
7171 self . input = & self . input [ first_non_numeric..] ;
7272 let length = length_str
@@ -75,7 +75,7 @@ impl<'de> Deserializer<'de> {
7575 Ok ( length)
7676 }
7777
78- fn parse_string ( & mut self ) -> Result < String > {
78+ fn parse_string ( & mut self ) -> Result < & str > {
7979 let first = self . next_byte ( ) ?;
8080 let kind = RespDataKind :: try_from ( first) . map_err ( |( ) | Error :: UnrecognizedStart ) ?;
8181 let result = match kind {
@@ -95,7 +95,7 @@ impl<'de> Deserializer<'de> {
9595 Ok ( result)
9696 }
9797
98- fn parse_simple_string ( & mut self ) -> Result < String > {
98+ fn parse_simple_string ( & mut self ) -> Result < & str > {
9999 let crlf_index = self . input . windows ( 2 ) . position ( |w| w == CRLF ) ;
100100 let result = if let Some ( index) = crlf_index {
101101 let result = & self . input [ ..index] ;
@@ -108,20 +108,20 @@ impl<'de> Deserializer<'de> {
108108 return Err ( Error :: UnexpectedEnd ) ;
109109 }
110110 self . expect_crlf ( ) ?;
111- Ok ( String :: from_utf8 ( result. to_vec ( ) ) ?)
111+ Ok ( str :: from_utf8 ( result) ?)
112112 }
113113
114- fn parse_bulk_string ( & mut self ) -> Result < String > {
114+ fn parse_bulk_string ( & mut self ) -> Result < & str > {
115115 if self . input . starts_with ( b"-1\r \n " ) {
116116 self . input = & self . input [ 4 ..] ; // Skip -1\r\n
117- return Ok ( String :: new ( ) ) ; // Null string
117+ return Ok ( "" ) ; // Null string
118118 }
119119 let length = self . expect_length ( ) ?;
120120 self . expect_crlf ( ) ?;
121121 let data = & self . input [ ..length] ;
122122 self . input = & self . input [ length..] ;
123123 self . expect_crlf ( ) ?;
124- Ok ( String :: from_utf8 ( data. to_vec ( ) ) ?)
124+ Ok ( str :: from_utf8 ( data) ?)
125125 }
126126
127127 /// Parse an number from the RESP format.
@@ -148,7 +148,7 @@ impl<'de> Deserializer<'de> {
148148 . iter ( )
149149 . position ( |b| !VALID_NUMERIC_CHARS . contains ( b) )
150150 . ok_or ( Error :: UnexpectedEnd ) ?;
151- let value_str = String :: from_utf8 ( self . input [ ..non_numeric_index] . to_vec ( ) ) ?;
151+ let value_str = str :: from_utf8 ( & self . input [ ..non_numeric_index] ) ?;
152152 self . input = & self . input [ non_numeric_index..] ;
153153 let value = value_str. parse :: < N > ( ) . map_err ( |_| Error :: UnexpectedByte {
154154 expected : "A valid integer string" . to_string ( ) ,
@@ -314,15 +314,16 @@ impl<'de> serde::de::Deserializer<'de> for &mut Deserializer<'de> {
314314 where
315315 V : serde:: de:: Visitor < ' de > ,
316316 {
317- self . deserialize_string ( visitor)
317+ let s = self . parse_string ( ) ?;
318+ visitor. visit_str ( s)
318319 }
319320
320321 fn deserialize_string < V > ( self , visitor : V ) -> Result < V :: Value >
321322 where
322323 V : serde:: de:: Visitor < ' de > ,
323324 {
324325 let s = self . parse_string ( ) ?;
325- visitor. visit_string ( s)
326+ visitor. visit_string ( s. to_string ( ) )
326327 }
327328
328329 fn deserialize_bytes < V > ( self , visitor : V ) -> Result < V :: Value >
@@ -346,9 +347,7 @@ impl<'de> serde::de::Deserializer<'de> for &mut Deserializer<'de> {
346347 ///
347348 /// As commented in `Serializer` implementation, this is a lossy
348349 /// representation. For example the values `Some(())` and `None` both
349- /// serialize as just `null`. Unfortunately this is typically what people
350- /// expect when working with JSON. Other formats are encouraged to behave
351- /// more intelligently if possible.
350+ /// serialize as just `null`.
352351 fn deserialize_option < V > ( self , visitor : V ) -> Result < V :: Value >
353352 where
354353 V : serde:: de:: Visitor < ' de > ,
@@ -416,7 +415,7 @@ impl<'de> serde::de::Deserializer<'de> for &mut Deserializer<'de> {
416415 visitor. visit_seq ( seq_visitor)
417416 }
418417
419- // Tuples look just like sequences in JSON . Some formats may be able to
418+ // Tuples look just like sequences. Some formats may be able to
420419 // represent tuples more efficiently.
421420 //
422421 // As indicated by the length parameter, the `Deserialize` implementation
@@ -429,7 +428,7 @@ impl<'de> serde::de::Deserializer<'de> for &mut Deserializer<'de> {
429428 self . deserialize_seq ( visitor)
430429 }
431430
432- // Tuple structs look just like sequences in JSON .
431+ // Tuple structs look just like sequences.
433432 fn deserialize_tuple_struct < V > (
434433 self ,
435434 _name : & ' static str ,
@@ -502,7 +501,7 @@ impl<'de> serde::de::Deserializer<'de> for &mut Deserializer<'de> {
502501 | RespDataKind :: VerbatimString => {
503502 // Visit a unit variant.
504503 let s = self . parse_string ( ) ?;
505- visitor. visit_enum ( s. as_str ( ) . into_deserializer ( ) )
504+ visitor. visit_enum ( s. into_deserializer ( ) )
506505 }
507506 RespDataKind :: Map | RespDataKind :: Attributes => {
508507 visitor. visit_enum ( EnumDeserializer :: new ( self ) )
@@ -515,9 +514,8 @@ impl<'de> serde::de::Deserializer<'de> for &mut Deserializer<'de> {
515514 }
516515
517516 // An identifier in Serde is the type that identifies a field of a struct or
518- // the variant of an enum. In JSON, struct fields and enum variants are
519- // represented as strings. In other formats they may be represented as
520- // numeric indices.
517+ // the variant of an enum. Struct fields and enum variants are
518+ // represented as strings.
521519 fn deserialize_identifier < V > ( self , visitor : V ) -> Result < V :: Value >
522520 where
523521 V : serde:: de:: Visitor < ' de > ,
@@ -664,7 +662,7 @@ impl<'de> serde::de::VariantAccess<'de> for EnumDeserializer<'_, 'de> {
664662 ) )
665663 }
666664
667- // Newtype variants are represented in JSON as `{ NAME: VALUE }` so
665+ // Newtype variants are represented as `{ NAME: VALUE }` so
668666 // deserialize the value here.
669667 fn newtype_variant_seed < T > ( self , seed : T ) -> Result < T :: Value >
670668 where
@@ -673,7 +671,7 @@ impl<'de> serde::de::VariantAccess<'de> for EnumDeserializer<'_, 'de> {
673671 seed. deserialize ( self . de )
674672 }
675673
676- // Tuple variants are represented in JSON as `{ NAME: [DATA...] }` so
674+ // Tuple variants are represented as `{ NAME: [DATA...] }` so
677675 // deserialize the sequence of data here.
678676 fn tuple_variant < V > ( self , _len : usize , visitor : V ) -> Result < V :: Value >
679677 where
@@ -682,7 +680,7 @@ impl<'de> serde::de::VariantAccess<'de> for EnumDeserializer<'_, 'de> {
682680 serde:: de:: Deserializer :: deserialize_seq ( self . de , visitor)
683681 }
684682
685- // Struct variants are represented in JSON as `{ NAME: { K: V, ... } }` so
683+ // Struct variants are represented as `{ NAME: { K: V, ... } }` so
686684 // deserialize the inner map here.
687685 fn struct_variant < V > ( self , _fields : & ' static [ & ' static str ] , visitor : V ) -> Result < V :: Value >
688686 where
0 commit comments