Skip to content

Commit b84e6ca

Browse files
committed
Improve wording of PR 2805 comments
1 parent 87a2fb0 commit b84e6ca

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

serde/src/private/de.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -1904,12 +1904,13 @@ mod content {
19041904
Content::None => visitor.visit_none(),
19051905
Content::Some(ref v) => visitor.visit_some(ContentRefDeserializer::new(v)),
19061906
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.
19131914
_ => visitor.visit_some(self),
19141915
}
19151916
}
@@ -1945,12 +1946,15 @@ mod content {
19451946
Content::Newtype(ref v) => {
19461947
visitor.visit_newtype_struct(ContentRefDeserializer::new(v))
19471948
}
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.
19541958
_ => visitor.visit_newtype_struct(self),
19551959
}
19561960
}

0 commit comments

Comments
 (0)