@@ -1904,12 +1904,13 @@ mod content {
1904
1904
Content :: None => visitor. visit_none ( ) ,
1905
1905
Content :: Some ( ref v) => visitor. visit_some ( ContentRefDeserializer :: new ( v) ) ,
1906
1906
Content :: Unit => visitor. visit_unit ( ) ,
1907
- // This case is necessary for formats which does not store
1908
- // marker of optionality of value, for example, JSON. When
1909
- // `deserialize_any` is requested from such formats, they will
1910
- // report value without using `Visitor::visit_some`, because
1911
- // they do not known in which contexts this value will be used.
1912
- // RON is example of format which preserve markers.
1907
+ // This case is to support data formats which do not encode an
1908
+ // indication whether a value is optional. An example of such a
1909
+ // format is JSON, and a counterexample is RON. When requesting
1910
+ // `deserialize_any` in JSON, the data format never performs
1911
+ // `Visitor::visit_some` but we still must be able to
1912
+ // deserialize the resulting Content into data structures with
1913
+ // optional fields.
1913
1914
_ => visitor. visit_some ( self ) ,
1914
1915
}
1915
1916
}
@@ -1945,12 +1946,15 @@ mod content {
1945
1946
Content :: Newtype ( ref v) => {
1946
1947
visitor. visit_newtype_struct ( ContentRefDeserializer :: new ( v) )
1947
1948
}
1948
- // This case is necessary for formats which does not store
1949
- // marker of a newtype, for example, JSON. When
1950
- // `deserialize_any` is requested from such formats, they will
1951
- // report value without using `Visitor::visit_newtype_struct`,
1952
- // because they do not known in which contexts this value will
1953
- // be used. RON is example of format which preserve markers.
1949
+ // This case is to support data formats that encode newtype
1950
+ // structs and their underlying data the same, with no
1951
+ // indication whether a newtype wrapper was present. For example
1952
+ // JSON does this, while RON does not. In RON a newtype's name
1953
+ // is included in the serialized representation and it knows to
1954
+ // call `Visitor::visit_newtype_struct` from `deserialize_any`.
1955
+ // JSON's `deserialize_any` never calls `visit_newtype_struct`
1956
+ // but in this code we still must be able to deserialize the
1957
+ // resulting Content into newtypes.
1954
1958
_ => visitor. visit_newtype_struct ( self ) ,
1955
1959
}
1956
1960
}
0 commit comments