Code works on rust playground but not in test code
What versions of serde
and serde_json
are in use? (Read Cargo.lock
or run the cargo tree
command.) Perhaps a old one with a bug is being used?
However, you don't need to use untagged
here. This should get the same result, but be more efficient and have better errors:
#[derive(Debug, Serialize, Deserialize)]
enum Rates {
#[serde(rename = "idr")]
Idr(CurrencyMap),
#[serde(rename = "usd")]
Usd(CurrencyMap),
}
serde(untagged)
should be avoided whenever possible, because it has poor error messages and it has to try every variant, which can be slow and also has to allocate temporary storage for all the data until it finds the right variant. It's much better to find a way to have a tag.
Source: View source