-
-
Notifications
You must be signed in to change notification settings - Fork 900
Deserializing runtime types #2609
Description
Sorry if this is not the right place to ask, but I've been stuck with this problem for a while and I'm not sure if it's possible to achieve this using Serde.
I have what is effectively a dynamic (runtime) representation of a struct. I want to use this representation to deserialize some data. To my understanding, the typical solution would be to treat it as a map and use deserialize_map alongside a custom Visitor, however I cannot do that as the serialization format I'm using has length-prefixed maps. The data I'm interested in deserializing does not treat these types as maps, and so there's no length prefix. Although serialize_struct is pretty much what I want, I can't use that either as the names of the members are not &'static str.
More concretely, here's a condensed example:
enum Kind {
Struct,
Number,
}
// Using this representation of the struct, I know the types and
// names of each member.
struct MyStructRepr {
name: String,
members: Vec<(String, Kind)>,
}
// The actual data into which I want to deserialize the input.
enum Data {
Struct {
members: Vec<Data>,
},
Number(usize),
String(String),
}Is this doable with Serde?