In Rust i am receiving data from a websocket. For simplicity it looks like this:
[1, {"a": ["1.2345", 5, "9.8765"]}]
The string i get from the websocket is indeed double-quoted 'floating point values' (thus in actuality strings), and unquoted integers.
I want to deserialize this object into a struct. But since the return array "a" is of mixed type, I can't use something like:
struct MyStruct {
id: i32,
a: [f64; 3],
}
So I thought let's define another struct:
struct Ask {
price: f64,
whole_lot_volume: i64,
lot_volume: f64
}
struct MyStruct {
id: i32,
a: Ask
}
But how should I write the deserializer for this? Looking at the serde
docs I understand that I should write a Visitor
for Ask
:
impl<'de> Visitor<'de> for Ask {
type Value = ...
}
But what would be the Value
type then?
So I'm sure I am not correctly understanding how the deserialization process works. Or is the fact that the Websocket returns an array of mixed types just incompatible with the serde deserialization process?