Expand description

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 Entrys.

Example

// 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.
  );
}

Structs

A currency entry.

An Iterator that scans currency entries.

Enums

The crate’s error type.