currencyapi_parse

Crates.iocurrencyapi_parse
lib.rscurrencyapi_parse
version0.1.1
sourcesrc
created_at2022-08-24 19:05:09.125521
updated_at2022-08-26 08:34:25.506676
descriptionQuick & dirty currencyapi parsing
homepagehttps://github.com/yehuthi/currencyapi_parse
repositoryhttps://github.com/yehuthi/currencyapi_parse
max_upload_size
id651763
size8,437
Yehuthi (yehuthi)

documentation

README

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>&currencies=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(()) }
Commit count: 0

cargo fmt