2 releases
0.1.1 | Aug 26, 2022 |
---|---|
0.1.0 | Aug 24, 2022 |
#263 in Finance
9KB
119 lines
currencyapi_parse
A library to parse currencyapi latest
response.
This library doesn't parse the response JSON, it just takes advantage of the regularity in the API. It has some sanity-checks for the regularity so it should be fine at least for casual use.
Usage
Use the Scanner
to iterate over currency Entry
s.
Example
# fn main() -> Result<(), Box<dyn std::error::Error>> {
// sample response from /latest USD & EUR: https://api.currencyapi.com/v3/latest?apikey=<apikey>¤cies=USD%2CEUR
let response = r#"{"meta":{"last_updated_at":"2022-08-23T23:59:59Z"},"data":{"EUR":{"code":"EUR","value":1.003367},"USD":{"code":"USD","value":1}}}"#;
let currencies = currencyapi_parse::Scanner::try_from(response)?;
for entry in currencies {
println!("{} = {:.2}",
std::str::from_utf8(&entry.currency)?,
response[entry].parse::<f64>()? // `Entry`s can conveniently index the response they come from.
);
}
# Ok(()) }
Dependencies
~105KB