Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serde support feature #5

Closed
IcanDivideBy0 opened this issue May 9, 2020 · 2 comments · Fixed by #6
Closed

Add serde support feature #5

IcanDivideBy0 opened this issue May 9, 2020 · 2 comments · Fixed by #6
Labels
enhancement New feature or request

Comments

@IcanDivideBy0
Copy link
Contributor

Hello,
I think serde support would be nice.

@IcanDivideBy0
Copy link
Contributor Author

IcanDivideBy0 commented May 9, 2020

Specifically, I'm trying to match currencies with open exchange rates API:

#[derive(Debug, Clone, Deserialize)]
struct Response {
    base: Currency,
    rates: HashMap<Currency, f32>,
}

let app_id = "SECRET";
let uri = format!(
    "http://openexchangerates.org/api/latest.json",
    app_id
);
// response:
// {
//     base: "USD",
//     rates: {
//         AED: 3.672538,
//         AFN: 66.809999,
//         ...
//     }
// }

#[derive(Debug, Clone, Deserialize)]
struct Response {
    base: Currency,
    rates: RatesMap,
}

let response: Response = reqwest::get(uri).await?.json().await?;

So for this example, Currency should also derive Eq and Hash.

Would you consider such a PR with serde behind a feature flag ?

@zbrox
Copy link
Owner

zbrox commented May 9, 2020

Sounds great!

@zbrox zbrox added the enhancement New feature or request label May 9, 2020
@zbrox zbrox closed this as completed May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants