File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -1938,10 +1938,17 @@ mod content {
1938
1938
where
1939
1939
V : Visitor < ' de > ,
1940
1940
{
1941
+ // Covered by tests/test_enum_untagged.rs
1942
+ // newtype_struct
1941
1943
match * self . content {
1942
1944
Content :: Newtype ( ref v) => {
1943
1945
visitor. visit_newtype_struct ( ContentRefDeserializer :: new ( v) )
1944
1946
}
1947
+ // This case is necessary for formats which does not store marker of a newtype,
1948
+ // for example, JSON. When `deserialize_any` is requested from such formats, they will
1949
+ // report value without using `Visitor::visit_newtype_struct`, because they do not
1950
+ // known in which contexts this value will be used.
1951
+ // RON is example of format which preserve markers.
1945
1952
_ => visitor. visit_newtype_struct ( self ) ,
1946
1953
}
1947
1954
}
Original file line number Diff line number Diff line change @@ -104,6 +104,7 @@ fn newtype_unit_and_empty_map() {
104
104
) ;
105
105
}
106
106
107
+ // Reaches crate::private::de::content::ContentRefDeserializer::deserialize_newtype_struct
107
108
#[ test]
108
109
fn newtype_struct ( ) {
109
110
#[ derive( Debug , PartialEq , Serialize , Deserialize ) ]
@@ -116,15 +117,21 @@ fn newtype_struct() {
116
117
Null ,
117
118
}
118
119
120
+ let value = E :: Newtype ( NewtypeStruct ( 5 ) ) ;
121
+
122
+ // Content::Newtype case
119
123
assert_tokens (
120
- & E :: Newtype ( NewtypeStruct ( 5 ) ) ,
124
+ & value ,
121
125
& [
122
126
Token :: NewtypeStruct {
123
127
name : "NewtypeStruct" ,
124
128
} ,
125
129
Token :: U32 ( 5 ) ,
126
130
] ,
127
131
) ;
132
+
133
+ // _ case
134
+ assert_de_tokens ( & value, & [ Token :: U32 ( 5 ) ] ) ;
128
135
}
129
136
130
137
#[ test]
You can’t perform that action at this time.
0 commit comments