Skip to main content

Module de

Module de 

Source
Expand description

Reading an answer set in one pass.

The decoder walks the wire format directly instead of building a value and then interpreting it: an answer’s kind is known from the member that names it, so the visitor that reads it can be chosen before its contents are parsed, and a score’s integer level keys become integers without a string ever existing.

The field path an error reports is built as the walk descends, which is why a failure deep in the answers can name the field it failed at rather than the object that contained it.

JSON objects are unordered, so an answer’s type may also arrive after the members it governs. Those members are then held as the raw text they arrived as - a slice of the response body, not a copy - and parsed once the type is known. Reading them eagerly instead would fail the whole response whenever an answer of a future type happened to reuse a member name with a different shape, which is exactly the answer this decoder promises to skip.

AnswerSet is the seam between this walk and what the answers decode into: Answers reads them into a lookup by name, and a question set declared as a struct reads each answer straight into its field.

Structs§

AnswerContext
What the decoder knows about the answers before it reads the first one.

Traits§

AnswerSet
A type the answers object of a response decodes into.