@@ -956,25 +956,28 @@ impl<'a, W: fmt::Write> ser::Serializer for &'a mut Serializer<W> {
956956 self . start_indent ( ) ?;
957957 }
958958
959- Ok ( Compound :: new ( self , false ) )
959+ Ok ( Compound :: new ( self , Some ( ']' ) ) )
960960 }
961961
962962 fn serialize_tuple ( self , len : usize ) -> Result < Self :: SerializeTuple > {
963963 let old_newtype_variant = self . newtype_variant ;
964964 self . newtype_variant = false ;
965965 self . implicit_some_depth = 0 ;
966966
967- if !old_newtype_variant {
967+ let closing = if old_newtype_variant {
968+ None
969+ } else {
968970 self . output . write_char ( '(' ) ?;
969- }
971+ Some ( ')' )
972+ } ;
970973
971974 if self . separate_tuple_members ( ) {
972975 self . is_empty = Some ( len == 0 ) ;
973976
974977 self . start_indent ( ) ?;
975978 }
976979
977- Ok ( Compound :: new ( self , old_newtype_variant ) )
980+ Ok ( Compound :: new ( self , closing ) )
978981 }
979982
980983 fn serialize_tuple_struct (
@@ -1011,7 +1014,7 @@ impl<'a, W: fmt::Write> ser::Serializer for &'a mut Serializer<W> {
10111014 self . start_indent ( ) ?;
10121015 }
10131016
1014- Ok ( Compound :: new ( self , false ) )
1017+ Ok ( Compound :: new ( self , Some ( ')' ) ) )
10151018 }
10161019
10171020 fn serialize_map ( self , len : Option < usize > ) -> Result < Self :: SerializeMap > {
@@ -1028,31 +1031,37 @@ impl<'a, W: fmt::Write> ser::Serializer for &'a mut Serializer<W> {
10281031 self . start_indent ( ) ?;
10291032 }
10301033
1031- Ok ( Compound :: new ( self , false ) )
1034+ Ok ( Compound :: new ( self , Some ( '}' ) ) )
10321035 }
10331036
10341037 fn serialize_struct ( self , name : & ' static str , len : usize ) -> Result < Self :: SerializeStruct > {
10351038 let old_newtype_variant = self . newtype_variant ;
10361039 self . newtype_variant = false ;
10371040 self . implicit_some_depth = 0 ;
10381041
1039- if old_newtype_variant {
1042+ let closing = if self . extensions ( ) . contains ( Extensions :: BRACED_STRUCTS ) {
1043+ self . write_identifier ( name) ?;
1044+ self . output . write_char ( '{' ) ?;
1045+ Some ( '}' )
1046+ } else if old_newtype_variant {
10401047 self . validate_identifier ( name) ?;
1048+ None
10411049 } else {
10421050 if self . struct_names ( ) {
10431051 self . write_identifier ( name) ?;
10441052 } else {
10451053 self . validate_identifier ( name) ?;
10461054 }
10471055 self . output . write_char ( '(' ) ?;
1048- }
1056+ Some ( ')' )
1057+ } ;
10491058
10501059 if !self . compact_structs ( ) {
10511060 self . is_empty = Some ( len == 0 ) ;
10521061 self . start_indent ( ) ?;
10531062 }
10541063
1055- Ok ( Compound :: new ( self , old_newtype_variant ) )
1064+ Ok ( Compound :: new ( self , closing ) )
10561065 }
10571066
10581067 fn serialize_struct_variant (
@@ -1067,14 +1076,21 @@ impl<'a, W: fmt::Write> ser::Serializer for &'a mut Serializer<W> {
10671076
10681077 self . validate_identifier ( name) ?;
10691078 self . write_identifier ( variant) ?;
1070- self . output . write_char ( '(' ) ?;
1079+
1080+ let closing = if self . extensions ( ) . contains ( Extensions :: BRACED_STRUCTS ) {
1081+ self . output . write_char ( '{' ) ?;
1082+ '}'
1083+ } else {
1084+ self . output . write_char ( '(' ) ?;
1085+ ')'
1086+ } ;
10711087
10721088 if !self . compact_structs ( ) {
10731089 self . is_empty = Some ( len == 0 ) ;
10741090 self . start_indent ( ) ?;
10751091 }
10761092
1077- Ok ( Compound :: new ( self , false ) )
1093+ Ok ( Compound :: new ( self , Some ( closing ) ) )
10781094 }
10791095}
10801096
@@ -1087,16 +1103,16 @@ enum State {
10871103pub struct Compound < ' a , W : fmt:: Write > {
10881104 ser : & ' a mut Serializer < W > ,
10891105 state : State ,
1090- newtype_variant : bool ,
1106+ closing : Option < char > ,
10911107 sequence_index : usize ,
10921108}
10931109
10941110impl < ' a , W : fmt:: Write > Compound < ' a , W > {
1095- fn new ( ser : & ' a mut Serializer < W > , newtype_variant : bool ) -> Self {
1111+ fn new ( ser : & ' a mut Serializer < W > , closing : Option < char > ) -> Self {
10961112 Compound {
10971113 ser,
10981114 state : State :: First ,
1099- newtype_variant ,
1115+ closing ,
11001116 sequence_index : 0 ,
11011117 }
11021118 }
@@ -1161,8 +1177,10 @@ impl<'a, W: fmt::Write> ser::SerializeSeq for Compound<'a, W> {
11611177 self . ser . end_indent ( ) ?;
11621178 }
11631179
1164- // seq always disables `self.newtype_variant`
1165- self . ser . output . write_char ( ']' ) ?;
1180+ if let Some ( closing) = self . closing {
1181+ self . ser . output . write_char ( closing) ?;
1182+ }
1183+
11661184 Ok ( ( ) )
11671185 }
11681186}
@@ -1210,8 +1228,8 @@ impl<'a, W: fmt::Write> ser::SerializeTuple for Compound<'a, W> {
12101228 self . ser . end_indent ( ) ?;
12111229 }
12121230
1213- if ! self . newtype_variant {
1214- self . ser . output . write_char ( ')' ) ?;
1231+ if let Some ( closing ) = self . closing {
1232+ self . ser . output . write_char ( closing ) ?;
12151233 }
12161234
12171235 Ok ( ( ) )
@@ -1309,8 +1327,10 @@ impl<'a, W: fmt::Write> ser::SerializeMap for Compound<'a, W> {
13091327 self . ser . end_indent ( ) ?;
13101328 }
13111329
1312- // map always disables `self.newtype_variant`
1313- self . ser . output . write_char ( '}' ) ?;
1330+ if let Some ( closing) = self . closing {
1331+ self . ser . output . write_char ( closing) ?;
1332+ }
1333+
13141334 Ok ( ( ) )
13151335 }
13161336}
@@ -1399,8 +1419,8 @@ impl<'a, W: fmt::Write> ser::SerializeStruct for Compound<'a, W> {
13991419 self . ser . end_indent ( ) ?;
14001420 }
14011421
1402- if ! self . newtype_variant {
1403- self . ser . output . write_char ( ')' ) ?;
1422+ if let Some ( closing ) = self . closing {
1423+ self . ser . output . write_char ( closing ) ?;
14041424 }
14051425
14061426 Ok ( ( ) )
0 commit comments