Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
Now, in practice, most deserializers will transparently forward themselves through visit_newtype_struct (json, yaml, MessagePack). However, because deserialize_newtype_struct has access to the type name being deserialized, and some deserializers will use this type name to inform custom behavior. For instance, in my (in-progress) implementation of KDL uses type names (including newtype names) to inform the names of nodes in homogeneous lists, bridging the gap between serde's collection-oriented model and KDL's node-oriented model. You can also see that the json and MessagePack serde implementations use special typenames to opt-in to custom behavior (like serde-json's raw-value feature).
Step 1: The Deserialize type requests data from the Deserializer with one of the deserialize_type methods. This gives it an opportunity to provide certain metadata about the type: structs provide a list of fields, enums provide a list of variants, tuples provide a length, etc. Some data formats (notably bincode) require this metadata to drive deserializing, as the wire format is not self-describing. Crucially, the Deserialize type also provides a visitor that is capable of receiving the requested data from the Deserializer.