I want to use Serde to serialize a data structure that is generic.
The users of my library should be able to provide their own structure that implements Serialize
and Deserialize
. I should be able to get back the original type information for the value that they serialized the data with.
How would I go about doing this?
I have tried something like this:
#[derive(Serialize, Deserialize)]
struct Message<V> {
key: Key,
value: V,
}
I want to get back the type of V
after I deserialize the data.
Is this the way to do it or am I way off track?
I want the user to be able to extend the possible values/types. I want the behavior of enums, but flexibility for the user to add their own structs as possible candidates. Similar to this code but they all need unique ids.