I have a string with a format that I can't change.
The format is: <dict>;<dict>;<dict>
With each <dict> being comma seperated key and values: key1,12345,key2,09244,key3,0,key4,datadata, keyname,value,keyname,value
The dict has a non-constant number of fields, and the string can have an unlimited amount of these dicts.
I have already written a parser by looping through each dict with the split() function, but it is very ugly and I would like to improve it by using Serde and implementing the Deserialize trait myself.
Another problem is that an dict can have many keys which I would like to deserialize into structs. But each dict can represent a diffrent struct with their own property.
For example: dict has id,10,time,10440, I would like to deserialize it to Time as it has a time key.
For id,2948,action,10, I would like to deserialize it to Action as it has a action key.
But for some of the structs, they have common keys, so I cannot easily distinguish between structs.
For id,11,time,5320,duration,1055, I would like to deserialize it to Length even when there's a time because it has duration.
Etc...
I have considered a large struct with many Option<>s, but first of all, a dict can have 100+ different fields (not all of them at once), and a string can have as much as 1mil dicts or even larger and there's usually multiple strings like this (about 20).
From what I've read, Option<>s still take up the same amount of memory even if it is None, so memory would be a problem with the million of large structs with only a small part of their allocated memory used.
Should I even have a custom Deserializer for the string? As the string is only a array.
Or should I make a Deserializer for the dicts instead?
And if I should make a Deserializer, how should I make it deserialize into enum depending on fields?