@@ -31,9 +31,8 @@ pub struct SeqSerializer {
3131 items : Vec < Value > ,
3232}
3333
34- pub struct SeqVariantSerializer < ' a > {
34+ pub struct SeqVariantSerializer {
3535 index : u32 ,
36- variant : & ' a str ,
3736 items : Vec < Value > ,
3837}
3938
@@ -46,9 +45,8 @@ pub struct StructSerializer {
4645 fields : Vec < ( String , Value ) > ,
4746}
4847
49- pub struct StructVariantSerializer < ' a > {
48+ pub struct StructVariantSerializer {
5049 index : u32 ,
51- variant : & ' a str ,
5250 fields : Vec < ( String , Value ) > ,
5351}
5452
@@ -63,15 +61,14 @@ impl SeqSerializer {
6361 }
6462}
6563
66- impl < ' a > SeqVariantSerializer < ' a > {
67- pub fn new ( index : u32 , variant : & ' a str , len : Option < usize > ) -> SeqVariantSerializer < ' a > {
64+ impl SeqVariantSerializer {
65+ pub fn new ( index : u32 , len : Option < usize > ) -> SeqVariantSerializer {
6866 let items = match len {
6967 Some ( len) => Vec :: with_capacity ( len) ,
7068 None => Vec :: new ( ) ,
7169 } ;
7270 SeqVariantSerializer {
7371 index,
74- variant,
7572 items,
7673 }
7774 }
@@ -96,11 +93,10 @@ impl StructSerializer {
9693 }
9794}
9895
99- impl < ' a > StructVariantSerializer < ' a > {
100- pub fn new ( index : u32 , variant : & ' a str , len : usize ) -> StructVariantSerializer < ' a > {
96+ impl StructVariantSerializer {
97+ pub fn new ( index : u32 , len : usize ) -> StructVariantSerializer {
10198 StructVariantSerializer {
10299 index,
103- variant,
104100 fields : Vec :: with_capacity ( len) ,
105101 }
106102 }
@@ -112,10 +108,10 @@ impl<'b> ser::Serializer for &'b mut Serializer {
112108 type SerializeSeq = SeqSerializer ;
113109 type SerializeTuple = SeqSerializer ;
114110 type SerializeTupleStruct = SeqSerializer ;
115- type SerializeTupleVariant = SeqVariantSerializer < ' b > ;
111+ type SerializeTupleVariant = SeqVariantSerializer ;
116112 type SerializeMap = MapSerializer ;
117113 type SerializeStruct = StructSerializer ;
118- type SerializeStructVariant = StructVariantSerializer < ' b > ;
114+ type SerializeStructVariant = StructVariantSerializer ;
119115
120116 fn serialize_bool ( self , v : bool ) -> Result < Self :: Ok , Self :: Error > {
121117 Ok ( Value :: Boolean ( v) )
@@ -226,21 +222,15 @@ impl<'b> ser::Serializer for &'b mut Serializer {
226222
227223 fn serialize_newtype_variant < T > (
228224 self ,
229- _ : & ' static str ,
225+ _name : & ' static str ,
230226 index : u32 ,
231- variant : & ' static str ,
227+ _variant : & ' static str ,
232228 value : & T ,
233229 ) -> Result < Self :: Ok , Self :: Error >
234230 where
235231 T : Serialize + ?Sized ,
236232 {
237- Ok ( Value :: Record ( vec ! [
238- ( "type" . to_owned( ) , Value :: Enum ( index, variant. to_owned( ) ) ) ,
239- (
240- "value" . to_owned( ) ,
241- Value :: Union ( index, Box :: new( value. serialize( self ) ?) ) ,
242- ) ,
243- ] ) )
233+ Ok ( Value :: Union ( index, Box :: new ( value. serialize ( self ) ?) ) )
244234 }
245235
246236 fn serialize_seq ( self , len : Option < usize > ) -> Result < Self :: SerializeSeq , Self :: Error > {
@@ -261,12 +251,12 @@ impl<'b> ser::Serializer for &'b mut Serializer {
261251
262252 fn serialize_tuple_variant (
263253 self ,
264- _ : & ' static str ,
254+ _name : & ' static str ,
265255 index : u32 ,
266- variant : & ' static str ,
256+ _variant : & ' static str ,
267257 len : usize ,
268258 ) -> Result < Self :: SerializeTupleVariant , Self :: Error > {
269- Ok ( SeqVariantSerializer :: new ( index, variant , Some ( len) ) )
259+ Ok ( SeqVariantSerializer :: new ( index, Some ( len) ) )
270260 }
271261
272262 fn serialize_map ( self , len : Option < usize > ) -> Result < Self :: SerializeMap , Self :: Error > {
@@ -283,12 +273,12 @@ impl<'b> ser::Serializer for &'b mut Serializer {
283273
284274 fn serialize_struct_variant (
285275 self ,
286- _ : & ' static str ,
276+ _name : & ' static str ,
287277 index : u32 ,
288- variant : & ' static str ,
278+ _variant : & ' static str ,
289279 len : usize ,
290280 ) -> Result < Self :: SerializeStructVariant , Self :: Error > {
291- Ok ( StructVariantSerializer :: new ( index, variant , len) )
281+ Ok ( StructVariantSerializer :: new ( index, len) )
292282 }
293283
294284 fn is_human_readable ( & self ) -> bool {
@@ -346,11 +336,11 @@ impl ser::SerializeTupleStruct for SeqSerializer {
346336 }
347337}
348338
349- impl ser:: SerializeSeq for SeqVariantSerializer < ' _ > {
339+ impl ser:: SerializeTupleVariant for SeqVariantSerializer {
350340 type Ok = Value ;
351341 type Error = Error ;
352342
353- fn serialize_element < T > ( & mut self , value : & T ) -> Result < ( ) , Self :: Error >
343+ fn serialize_field < T > ( & mut self , value : & T ) -> Result < ( ) , Self :: Error >
354344 where
355345 T : Serialize + ?Sized ,
356346 {
@@ -362,29 +352,7 @@ impl ser::SerializeSeq for SeqVariantSerializer<'_> {
362352 }
363353
364354 fn end ( self ) -> Result < Self :: Ok , Self :: Error > {
365- Ok ( Value :: Record ( vec ! [
366- (
367- "type" . to_owned( ) ,
368- Value :: Enum ( self . index, self . variant. to_owned( ) ) ,
369- ) ,
370- ( "value" . to_owned( ) , Value :: Array ( self . items) ) ,
371- ] ) )
372- }
373- }
374-
375- impl ser:: SerializeTupleVariant for SeqVariantSerializer < ' _ > {
376- type Ok = Value ;
377- type Error = Error ;
378-
379- fn serialize_field < T > ( & mut self , value : & T ) -> Result < ( ) , Self :: Error >
380- where
381- T : Serialize + ?Sized ,
382- {
383- ser:: SerializeSeq :: serialize_element ( self , value)
384- }
385-
386- fn end ( self ) -> Result < Self :: Ok , Self :: Error > {
387- ser:: SerializeSeq :: end ( self )
355+ Ok ( Value :: Union ( self . index , Box :: new ( Value :: Array ( self . items ) ) ) )
388356 }
389357}
390358
@@ -447,7 +415,7 @@ impl ser::SerializeStruct for StructSerializer {
447415 }
448416}
449417
450- impl ser:: SerializeStructVariant for StructVariantSerializer < ' _ > {
418+ impl ser:: SerializeStructVariant for StructVariantSerializer {
451419 type Ok = Value ;
452420 type Error = Error ;
453421
@@ -463,16 +431,7 @@ impl ser::SerializeStructVariant for StructVariantSerializer<'_> {
463431 }
464432
465433 fn end ( self ) -> Result < Self :: Ok , Self :: Error > {
466- Ok ( Value :: Record ( vec ! [
467- (
468- "type" . to_owned( ) ,
469- Value :: Enum ( self . index, self . variant. to_owned( ) ) ,
470- ) ,
471- (
472- "value" . to_owned( ) ,
473- Value :: Union ( self . index, Box :: new( Value :: Record ( self . fields) ) ) ,
474- ) ,
475- ] ) )
434+ Ok ( Value :: Union ( self . index , Box :: new ( Value :: Record ( self . fields ) ) ) )
476435 }
477436}
478437
@@ -784,13 +743,7 @@ mod tests {
784743
785744 let expected = Value :: Record ( vec ! [ (
786745 "a" . to_owned( ) ,
787- Value :: Record ( vec![
788- ( "type" . to_owned( ) , Value :: Enum ( 0 , "Double" . to_owned( ) ) ) ,
789- (
790- "value" . to_owned( ) ,
791- Value :: Union ( 0 , Box :: new( Value :: Double ( 64.0 ) ) ) ,
792- ) ,
793- ] ) ,
746+ Value :: Union ( 0 , Box :: new( Value :: Double ( 64.0 ) ) ) ,
794747 ) ] ) ;
795748
796749 assert_eq ! (
@@ -846,19 +799,13 @@ mod tests {
846799 } ;
847800 let expected = Value :: Record ( vec ! [ (
848801 "a" . to_owned( ) ,
849- Value :: Record ( vec![
850- ( "type" . to_owned( ) , Value :: Enum ( 0 , "Val1" . to_owned( ) ) ) ,
851- (
852- "value" . to_owned( ) ,
853- Value :: Union (
854- 0 ,
855- Box :: new( Value :: Record ( vec![
856- ( "x" . to_owned( ) , Value :: Float ( 1.0 ) ) ,
857- ( "y" . to_owned( ) , Value :: Float ( 2.0 ) ) ,
858- ] ) ) ,
859- ) ,
860- ) ,
861- ] ) ,
802+ Value :: Union (
803+ 0 ,
804+ Box :: new( Value :: Record ( vec![
805+ ( "x" . to_owned( ) , Value :: Float ( 1.0 ) ) ,
806+ ( "y" . to_owned( ) , Value :: Float ( 2.0 ) ) ,
807+ ] ) ) ,
808+ ) ,
862809 ) ] ) ;
863810
864811 assert_eq ! (
@@ -960,17 +907,14 @@ mod tests {
960907
961908 let expected = Value :: Record ( vec ! [ (
962909 "a" . to_owned( ) ,
963- Value :: Record ( vec![
964- ( "type" . to_owned( ) , Value :: Enum ( 1 , "Val2" . to_owned( ) ) ) ,
965- (
966- "value" . to_owned( ) ,
967- Value :: Array ( vec![
968- Value :: Union ( 1 , Box :: new( Value :: Float ( 1.0 ) ) ) ,
969- Value :: Union ( 1 , Box :: new( Value :: Float ( 2.0 ) ) ) ,
970- Value :: Union ( 1 , Box :: new( Value :: Float ( 3.0 ) ) ) ,
971- ] ) ,
972- ) ,
973- ] ) ,
910+ Value :: Union (
911+ 1 ,
912+ Box :: new( Value :: Array ( vec![
913+ Value :: Union ( 1 , Box :: new( Value :: Float ( 1.0 ) ) ) ,
914+ Value :: Union ( 1 , Box :: new( Value :: Float ( 2.0 ) ) ) ,
915+ Value :: Union ( 1 , Box :: new( Value :: Float ( 3.0 ) ) ) ,
916+ ] ) ) ,
917+ ) ,
974918 ) ] ) ;
975919
976920 assert_eq ! (
0 commit comments