My question is pretty simple - what are the ways I can model a JSON response of, e.g., stock prices. Let's say I want to model a JSON response of a price query request that gives me stock names and prices, like:
{"AAPL": {"usd": 10}, "GOOG": {"usd": 20} ...}
If I model this with an enum together with serde
crate, it will require me to list a huge number of stock variants, and even if I'll somehow manage to do that, it will still be very inefficient because new stocks are added constantly and I won't be able to properly maintain the variants list. So the following is not feasible:
#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PriceResponse {
AAPL(HashMap<String, HashMap<String, f32>>),
GOOG(HashMap<String, HashMap<String, f32>>),
...
...
}
I do want to make use of rust's type system to make the response more "typed", but I don't know how to do it. Ideally, I want to get an enum or a struct back.