@@ -67,6 +67,11 @@ enum ExternallyTagged {
67
67
nested : Nested ,
68
68
string : & ' static str ,
69
69
} ,
70
+ Flatten {
71
+ #[ serde( flatten) ]
72
+ nested : Nested ,
73
+ string : & ' static str ,
74
+ } ,
70
75
/// `float` field serialized as textual content instead of a tag
71
76
Text {
72
77
#[ serde( rename = "$text" ) ]
@@ -80,22 +85,6 @@ enum ExternallyTagged {
80
85
} ,
81
86
}
82
87
83
- /// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to
84
- /// incorrect code generation when deriving `Deserialize`.
85
- ///
86
- /// TODO: Merge into main enum after fixing <https://github.com/serde-rs/serde/issues/2371>
87
- ///
88
- /// Anyway, deserialization of that type in roundtrip suffers from
89
- /// <https://github.com/serde-rs/serde/issues/1183>
90
- #[ derive( Debug , PartialEq , Deserialize , Serialize ) ]
91
- enum ExternallyTaggedWorkaround {
92
- Flatten {
93
- #[ serde( flatten) ]
94
- nested : Nested ,
95
- string : & ' static str ,
96
- } ,
97
- }
98
-
99
88
#[ derive( Debug , PartialEq , Deserialize , Serialize ) ]
100
89
#[ serde( tag = "tag" ) ]
101
90
enum InternallyTagged {
@@ -111,6 +100,11 @@ enum InternallyTagged {
111
100
nested : Nested ,
112
101
string : & ' static str ,
113
102
} ,
103
+ Flatten {
104
+ #[ serde( flatten) ]
105
+ nested : Nested ,
106
+ string : & ' static str ,
107
+ } ,
114
108
/// `float` field serialized as textual content instead of a tag
115
109
Text {
116
110
#[ serde( rename = "$text" ) ]
@@ -124,23 +118,6 @@ enum InternallyTagged {
124
118
} ,
125
119
}
126
120
127
- /// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to
128
- /// incorrect code generation when deriving `Deserialize`.
129
- ///
130
- /// TODO: Merge into main enum after fixing <https://github.com/serde-rs/serde/issues/2371>
131
- ///
132
- /// Anyway, deserialization of that type in roundtrip suffers from
133
- /// <https://github.com/serde-rs/serde/issues/1183>
134
- #[ derive( Debug , PartialEq , Serialize ) ]
135
- #[ serde( tag = "tag" ) ]
136
- enum InternallyTaggedWorkaround {
137
- Flatten {
138
- #[ serde( flatten) ]
139
- nested : Nested ,
140
- string : & ' static str ,
141
- } ,
142
- }
143
-
144
121
#[ derive( Debug , PartialEq , Deserialize , Serialize ) ]
145
122
#[ serde( tag = "tag" , content = "content" ) ]
146
123
enum AdjacentlyTagged {
@@ -155,6 +132,11 @@ enum AdjacentlyTagged {
155
132
nested : Nested ,
156
133
string : & ' static str ,
157
134
} ,
135
+ Flatten {
136
+ #[ serde( flatten) ]
137
+ nested : Nested ,
138
+ string : & ' static str ,
139
+ } ,
158
140
/// `float` field serialized as textual content instead of a tag
159
141
Text {
160
142
#[ serde( rename = "$text" ) ]
@@ -168,23 +150,6 @@ enum AdjacentlyTagged {
168
150
} ,
169
151
}
170
152
171
- /// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to
172
- /// incorrect code generation when deriving `Deserialize`.
173
- ///
174
- /// TODO: Merge into main enum after fixing <https://github.com/serde-rs/serde/issues/2371>
175
- ///
176
- /// Anyway, deserialization of that type in roundtrip suffers from
177
- /// <https://github.com/serde-rs/serde/issues/1183>
178
- #[ derive( Serialize ) ]
179
- #[ serde( tag = "tag" , content = "content" ) ]
180
- enum AdjacentlyTaggedWorkaround {
181
- Flatten {
182
- #[ serde( flatten) ]
183
- nested : Nested ,
184
- string : & ' static str ,
185
- } ,
186
- }
187
-
188
153
#[ derive( Debug , PartialEq , Deserialize , Serialize ) ]
189
154
#[ serde( untagged) ]
190
155
enum Untagged {
@@ -199,6 +164,11 @@ enum Untagged {
199
164
nested : Nested ,
200
165
string : & ' static str ,
201
166
} ,
167
+ Flatten {
168
+ #[ serde( flatten) ]
169
+ nested : Nested ,
170
+ string : & ' static str ,
171
+ } ,
202
172
/// `float` field serialized as textual content instead of a tag
203
173
Text {
204
174
#[ serde( rename = "$text" ) ]
@@ -212,23 +182,6 @@ enum Untagged {
212
182
} ,
213
183
}
214
184
215
- /// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to
216
- /// incorrect code generation when deriving `Deserialize`.
217
- ///
218
- /// TODO: Merge into main enum after fixing <https://github.com/serde-rs/serde/issues/2371>
219
- ///
220
- /// Anyway, deserialization of that type in roundtrip suffers from
221
- /// <https://github.com/serde-rs/serde/issues/1183>
222
- #[ derive( Serialize ) ]
223
- #[ serde( untagged) ]
224
- enum UntaggedWorkaround {
225
- Flatten {
226
- #[ serde( flatten) ]
227
- nested : Nested ,
228
- string : & ' static str ,
229
- } ,
230
- }
231
-
232
185
mod without_root {
233
186
use super :: * ;
234
187
use pretty_assertions:: assert_eq;
@@ -443,7 +396,7 @@ mod without_root {
443
396
// NOTE: Cannot be deserialized in roundtrip due to
444
397
// https://github.com/serde-rs/serde/issues/1183
445
398
serialize_as_only ! ( flatten_struct:
446
- ExternallyTaggedWorkaround :: Flatten {
399
+ ExternallyTagged :: Flatten {
447
400
nested: Nested { float: 42.0 } ,
448
401
string: "answer" ,
449
402
}
@@ -822,7 +775,7 @@ mod without_root {
822
775
// NOTE: Cannot be deserialized in roundtrip due to
823
776
// https://github.com/serde-rs/serde/issues/1183
824
777
serialize_as_only ! ( flatten_struct:
825
- Root { field: ExternallyTaggedWorkaround :: Flatten {
778
+ Root { field: ExternallyTagged :: Flatten {
826
779
nested: Nested { float: 42.0 } ,
827
780
string: "answer" ,
828
781
} }
@@ -914,7 +867,7 @@ mod without_root {
914
867
// NOTE: Cannot be deserialized in roundtrip due to
915
868
// https://github.com/serde-rs/serde/issues/1183
916
869
serialize_as_only ! ( flatten_struct:
917
- Root { field: Inner { inner: ExternallyTaggedWorkaround :: Flatten {
870
+ Root { field: Inner { inner: ExternallyTagged :: Flatten {
918
871
nested: Nested { float: 42.0 } ,
919
872
string: "answer" ,
920
873
} } }
@@ -996,12 +949,12 @@ mod without_root {
996
949
=> Unsupported ( "cannot serialize enum struct variant `ExternallyTagged::Holder` as text content value" ) ,
997
950
"<Root" ) ;
998
951
err ! ( flatten_struct:
999
- Root { field: ExternallyTaggedWorkaround :: Flatten {
952
+ Root { field: ExternallyTagged :: Flatten {
1000
953
nested: Nested { float: 42.0 } ,
1001
954
string: "answer" ,
1002
955
} }
1003
956
// Flatten enum struct variants represented as newtype variants containing maps
1004
- => Unsupported ( "cannot serialize enum newtype variant `ExternallyTaggedWorkaround ::Flatten` as text content value" ) ,
957
+ => Unsupported ( "cannot serialize enum newtype variant `ExternallyTagged ::Flatten` as text content value" ) ,
1005
958
"<Root" ) ;
1006
959
err ! ( empty_struct:
1007
960
Root { field: ExternallyTagged :: Empty { } }
@@ -1055,12 +1008,12 @@ mod without_root {
1055
1008
=> Unsupported ( "cannot serialize enum struct variant `ExternallyTagged::Holder` as text content value" ) ,
1056
1009
"<Root" ) ;
1057
1010
err ! ( flatten_struct:
1058
- Root { field: Inner { inner: ExternallyTaggedWorkaround :: Flatten {
1011
+ Root { field: Inner { inner: ExternallyTagged :: Flatten {
1059
1012
nested: Nested { float: 42.0 } ,
1060
1013
string: "answer" ,
1061
1014
} } }
1062
1015
// Flatten enum struct variants represented as newtype variants containing maps
1063
- => Unsupported ( "cannot serialize enum newtype variant `ExternallyTaggedWorkaround ::Flatten` as text content value" ) ,
1016
+ => Unsupported ( "cannot serialize enum newtype variant `ExternallyTagged ::Flatten` as text content value" ) ,
1064
1017
"<Root" ) ;
1065
1018
err ! ( empty_struct:
1066
1019
Root { field: Inner { inner: ExternallyTagged :: Empty { } } }
@@ -1125,7 +1078,7 @@ mod without_root {
1125
1078
// serde serializes flatten structs as maps, and we do not support
1126
1079
// serialization of maps without root tag
1127
1080
err ! ( flatten_struct:
1128
- InternallyTaggedWorkaround :: Flatten {
1081
+ InternallyTagged :: Flatten {
1129
1082
nested: Nested { float: 42.0 } ,
1130
1083
string: "answer" ,
1131
1084
}
@@ -1201,17 +1154,17 @@ mod without_root {
1201
1154
// NOTE: Cannot be deserialized in roundtrip due to
1202
1155
// https://github.com/serde-rs/serde/issues/1183
1203
1156
serialize_as_only ! ( flatten_struct:
1204
- AdjacentlyTaggedWorkaround :: Flatten {
1157
+ AdjacentlyTagged :: Flatten {
1205
1158
nested: Nested { float: 42.0 } ,
1206
1159
string: "answer" ,
1207
1160
}
1208
- => "<AdjacentlyTaggedWorkaround >\
1161
+ => "<AdjacentlyTagged >\
1209
1162
<tag>Flatten</tag>\
1210
1163
<content>\
1211
1164
<float>42</float>\
1212
1165
<string>answer</string>\
1213
1166
</content>\
1214
- </AdjacentlyTaggedWorkaround >") ;
1167
+ </AdjacentlyTagged >") ;
1215
1168
serialize_as ! ( empty_struct:
1216
1169
AdjacentlyTagged :: Empty { }
1217
1170
=> "<AdjacentlyTagged>\
@@ -1272,7 +1225,7 @@ mod without_root {
1272
1225
// serde serializes flatten structs as maps, and we do not support
1273
1226
// serialization of maps without root tag
1274
1227
err ! ( flatten_struct:
1275
- UntaggedWorkaround :: Flatten {
1228
+ Untagged :: Flatten {
1276
1229
nested: Nested { float: 42.0 } ,
1277
1230
string: "answer" ,
1278
1231
}
@@ -1470,7 +1423,7 @@ mod without_root {
1470
1423
<string>answer</string>\n \
1471
1424
</Holder>") ;
1472
1425
serialize_as ! ( flatten_struct:
1473
- ExternallyTaggedWorkaround :: Flatten {
1426
+ ExternallyTagged :: Flatten {
1474
1427
nested: Nested { float: 42.0 } ,
1475
1428
string: "answer" ,
1476
1429
}
@@ -1575,7 +1528,7 @@ mod without_root {
1575
1528
// serde serializes flatten structs as maps, and we do not support
1576
1529
// serialization of maps without root tag
1577
1530
err ! ( flatten_struct:
1578
- InternallyTaggedWorkaround :: Flatten {
1531
+ InternallyTagged :: Flatten {
1579
1532
nested: Nested { float: 42.0 } ,
1580
1533
string: "answer" ,
1581
1534
}
@@ -1647,17 +1600,17 @@ mod without_root {
1647
1600
</content>\n \
1648
1601
</AdjacentlyTagged>") ;
1649
1602
serialize_as ! ( flatten_struct:
1650
- AdjacentlyTaggedWorkaround :: Flatten {
1603
+ AdjacentlyTagged :: Flatten {
1651
1604
nested: Nested { float: 42.0 } ,
1652
1605
string: "answer" ,
1653
1606
}
1654
- => "<AdjacentlyTaggedWorkaround >\n \
1607
+ => "<AdjacentlyTagged >\n \
1655
1608
<tag>Flatten</tag>\n \
1656
1609
<content>\n \
1657
1610
<float>42</float>\n \
1658
1611
<string>answer</string>\n \
1659
1612
</content>\n \
1660
- </AdjacentlyTaggedWorkaround >") ;
1613
+ </AdjacentlyTagged >") ;
1661
1614
serialize_as ! ( empty_struct:
1662
1615
AdjacentlyTagged :: Empty { }
1663
1616
=> "<AdjacentlyTagged>\n \
@@ -1710,7 +1663,7 @@ mod without_root {
1710
1663
<string>answer</string>\n \
1711
1664
</Untagged>") ;
1712
1665
err ! ( flatten_struct:
1713
- UntaggedWorkaround :: Flatten {
1666
+ Untagged :: Flatten {
1714
1667
nested: Nested { float: 42.0 } ,
1715
1668
string: "answer" ,
1716
1669
}
@@ -2053,7 +2006,7 @@ mod with_root {
2053
2006
// NOTE: Cannot be deserialized in roundtrip due to
2054
2007
// https://github.com/serde-rs/serde/issues/1183
2055
2008
serialize_as_only ! ( flatten_struct:
2056
- ExternallyTaggedWorkaround :: Flatten {
2009
+ ExternallyTagged :: Flatten {
2057
2010
nested: Nested { float: 42.0 } ,
2058
2011
string: "answer" ,
2059
2012
}
@@ -2167,7 +2120,7 @@ mod with_root {
2167
2120
// NOTE: Cannot be deserialized in roundtrip due to
2168
2121
// https://github.com/serde-rs/serde/issues/1183
2169
2122
serialize_as_only ! ( flatten_struct:
2170
- InternallyTaggedWorkaround :: Flatten {
2123
+ InternallyTagged :: Flatten {
2171
2124
nested: Nested { float: 42.0 } ,
2172
2125
string: "answer" ,
2173
2126
}
@@ -2247,7 +2200,7 @@ mod with_root {
2247
2200
// NOTE: Cannot be deserialized in roundtrip due to
2248
2201
// https://github.com/serde-rs/serde/issues/1183
2249
2202
serialize_as_only ! ( flatten_struct:
2250
- AdjacentlyTaggedWorkaround :: Flatten {
2203
+ AdjacentlyTagged :: Flatten {
2251
2204
nested: Nested { float: 42.0 } ,
2252
2205
string: "answer" ,
2253
2206
}
@@ -2326,7 +2279,7 @@ mod with_root {
2326
2279
// NOTE: Cannot be deserialized in roundtrip due to
2327
2280
// https://github.com/serde-rs/serde/issues/1183
2328
2281
serialize_as_only ! ( flatten_struct:
2329
- UntaggedWorkaround :: Flatten {
2282
+ Untagged :: Flatten {
2330
2283
nested: Nested { float: 42.0 } ,
2331
2284
string: "answer" ,
2332
2285
}
0 commit comments