I have a JSON file with some repeating object structure and strings like below.
{
"array": [
{
"data": [
"blih",
"blah",
"bloh"
]
},
...
]
}
My best understanding of Rust would be to deserialize the JSON into a set of structs and then copy the data into another set of structs that includes Rc
:
// json structs
#[derive(Serialize, Deserialize)]
struct ArrayJson {
array: Vec<DataJson>,
}
#[derive(Serialize, Deserialize)]
struct DataJson {
data: Vec<String>,
}
// rc structs
struct ArrayRc {
array: Vec<DataRc>,
}
struct DataRc {
data: Vec<Rc<String>>,
}
Is there a way I can not create two sets of structs and just one?
Update: I believe the rc
of serde is not what I want as it serializes and deserializes the actual Rc
Arc
struct.
Serializing a data structure containing reference-counted pointers will serialize a copy of the inner value of the pointer each time a pointer is referenced within the data structure. Serialization will not attempt to deduplicate these repeated data.
Deserializing a data structure containing reference-counted pointers will not attempt to deduplicate references to the same data. Every deserialized pointer will end up with a strong count of 1.
I only care about the Rc
struct on the Rust side, hence why I believe I will need two structs.