Skip to content

Commit

Permalink
Improve wording of PR 2805 comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 24, 2024
1 parent 87a2fb0 commit b84e6ca
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions serde/src/private/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1904,12 +1904,13 @@ mod content {
Content::None => visitor.visit_none(),
Content::Some(ref v) => visitor.visit_some(ContentRefDeserializer::new(v)),
Content::Unit => visitor.visit_unit(),
// This case is necessary for formats which does not store
// marker of optionality of value, for example, JSON. When
// `deserialize_any` is requested from such formats, they will
// report value without using `Visitor::visit_some`, because
// they do not known in which contexts this value will be used.
// RON is example of format which preserve markers.
// This case is to support data formats which do not encode an
// indication whether a value is optional. An example of such a
// format is JSON, and a counterexample is RON. When requesting
// `deserialize_any` in JSON, the data format never performs
// `Visitor::visit_some` but we still must be able to
// deserialize the resulting Content into data structures with
// optional fields.
_ => visitor.visit_some(self),
}
}
Expand Down Expand Up @@ -1945,12 +1946,15 @@ mod content {
Content::Newtype(ref v) => {
visitor.visit_newtype_struct(ContentRefDeserializer::new(v))
}
// This case is necessary for formats which does not store
// marker of a newtype, for example, JSON. When
// `deserialize_any` is requested from such formats, they will
// report value without using `Visitor::visit_newtype_struct`,
// because they do not known in which contexts this value will
// be used. RON is example of format which preserve markers.
// This case is to support data formats that encode newtype
// structs and their underlying data the same, with no
// indication whether a newtype wrapper was present. For example
// JSON does this, while RON does not. In RON a newtype's name
// is included in the serialized representation and it knows to
// call `Visitor::visit_newtype_struct` from `deserialize_any`.
// JSON's `deserialize_any` never calls `visit_newtype_struct`
// but in this code we still must be able to deserialize the
// resulting Content into newtypes.
_ => visitor.visit_newtype_struct(self),
}
}
Expand Down

0 comments on commit b84e6ca

Please sign in to comment.