I have data structured in two different ways:
1: JSON
{
"key1": 40,
"key2": 50
{,
{
"key1": 41,
"key2": 51
}
2: nested array
[[40,50],[41,51]]
The goal is to deserialize this data (I receive both as Strings) into an Struct that looks like this:
struct data {
key1: Vec<i8>, // -> [40,41]
key2: Vec<i8> // -> [50,51]
}
I already have 2 methods for deserializing each type of data, but the problem is that for the first one, I have to create an intermediate Struct and collect them in a Vec to then iterate over this Vec pushing each element to its specific Vecs in the final Struct.
For the second one, I deserialize to a Vec<Vec<i8>> to then iterate again transposing into the final Struct element by element.
I read through all serde documentation and tried to find examples, but couldn't find a way of pushing directly to the final Vecs of the Struct without an intermediate step.
Does serde supports this? If so, how it's implemented?