I get JSON from the API, and the response can be one of 30 types. Each type has a unique set of fields, but all answers have a type field, which indicates what type it is.
My approach is to use serde . I create a structure for each type of response and make them decodeable. Once I understood how to choose which structure should be used for the message just received?
At the moment, I have created another TypeStruct structure with a single field for type . I decode the JSON in TypeStruct and then select the appropriate structure for the received message based on the type value and decodes the message again.
I would like to get rid of this duplication of decoding.
source share