Code works on rust playground but not in test code

PressRex profile image
by PressRex
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

PressRex profile image
by PressRex

Subscribe to New Posts

Lorem ultrices malesuada sapien amet pulvinar quis. Feugiat etiam ullamcorper pharetra vitae nibh enim vel.

Success! Now Check Your Email

To complete Subscribe, click the confirmation link in your inbox. If it doesn’t arrive within 3 minutes, check your spam folder.

Ok, Thanks

Read More