File tree 3 files changed +38
-6
lines changed
3 files changed +38
-6
lines changed Original file line number Diff line number Diff line change @@ -2710,6 +2710,17 @@ where
2710
2710
visitor. visit_unit ( )
2711
2711
}
2712
2712
2713
+ fn deserialize_unit_struct < V > (
2714
+ self ,
2715
+ _name : & ' static str ,
2716
+ visitor : V ,
2717
+ ) -> Result < V :: Value , Self :: Error >
2718
+ where
2719
+ V : Visitor < ' de > ,
2720
+ {
2721
+ visitor. visit_unit ( )
2722
+ }
2723
+
2713
2724
fn deserialize_ignored_any < V > ( self , visitor : V ) -> Result < V :: Value , Self :: Error >
2714
2725
where
2715
2726
V : Visitor < ' de > ,
@@ -2734,7 +2745,6 @@ where
2734
2745
deserialize_string( )
2735
2746
deserialize_bytes( )
2736
2747
deserialize_byte_buf( )
2737
- deserialize_unit_struct( & ' static str )
2738
2748
deserialize_seq( )
2739
2749
deserialize_tuple( usize )
2740
2750
deserialize_tuple_struct( & ' static str , usize )
Original file line number Diff line number Diff line change @@ -51,8 +51,6 @@ enum Unsupported {
51
51
String ,
52
52
ByteArray ,
53
53
Optional ,
54
- #[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
55
- UnitStruct ,
56
54
Sequence ,
57
55
Tuple ,
58
56
TupleStruct ,
@@ -69,8 +67,6 @@ impl Display for Unsupported {
69
67
Unsupported :: String => formatter. write_str ( "a string" ) ,
70
68
Unsupported :: ByteArray => formatter. write_str ( "a byte array" ) ,
71
69
Unsupported :: Optional => formatter. write_str ( "an optional" ) ,
72
- #[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
73
- Unsupported :: UnitStruct => formatter. write_str ( "unit struct" ) ,
74
70
Unsupported :: Sequence => formatter. write_str ( "a sequence" ) ,
75
71
Unsupported :: Tuple => formatter. write_str ( "a tuple" ) ,
76
72
Unsupported :: TupleStruct => formatter. write_str ( "a tuple struct" ) ,
@@ -1092,7 +1088,7 @@ where
1092
1088
}
1093
1089
1094
1090
fn serialize_unit_struct ( self , _: & ' static str ) -> Result < Self :: Ok , Self :: Error > {
1095
- Err ( Self :: bad_type ( Unsupported :: UnitStruct ) )
1091
+ Ok ( ( ) )
1096
1092
}
1097
1093
1098
1094
fn serialize_unit_variant (
Original file line number Diff line number Diff line change @@ -1815,6 +1815,32 @@ fn test_flatten_unit() {
1815
1815
) ;
1816
1816
}
1817
1817
1818
+ #[ test]
1819
+ fn test_flatten_unit_struct ( ) {
1820
+ #[ derive( Debug , PartialEq , Serialize , Deserialize ) ]
1821
+ struct Response < T > {
1822
+ #[ serde( flatten) ]
1823
+ data : T ,
1824
+ status : usize ,
1825
+ }
1826
+
1827
+ #[ derive( Debug , PartialEq , Serialize , Deserialize ) ]
1828
+ struct Unit ;
1829
+
1830
+ assert_tokens (
1831
+ & Response {
1832
+ data : Unit ,
1833
+ status : 0 ,
1834
+ } ,
1835
+ & [
1836
+ Token :: Map { len : None } ,
1837
+ Token :: Str ( "status" ) ,
1838
+ Token :: U64 ( 0 ) ,
1839
+ Token :: MapEnd ,
1840
+ ] ,
1841
+ ) ;
1842
+ }
1843
+
1818
1844
#[ test]
1819
1845
fn test_flatten_unsupported_type ( ) {
1820
1846
#[ derive( Debug , PartialEq , Serialize , Deserialize ) ]
You can’t perform that action at this time.
0 commit comments