cashify

Crates.iocashify
lib.rscashify
version0.1.1
sourcesrc
created_at2020-06-02 08:21:02.123176
updated_at2020-06-02 08:28:37.971564
descriptionLightweight currency conversion library.
homepagehttps://github.com/xxczaki/cashify-rs
repositoryhttps://github.com/xxczaki/cashify-rs
max_upload_size
id249167
size8,331
Antoni Kępiński (xxczaki)

documentation

https://docs.rs/cashify

README

Cashify 💸

Lightweight currency conversion library.

Build Status Crates cashify at docs.rs

This Rust crate is a port of the Cashify npm package from the same author. API is not the same.

Documentation

Installation

Simply add the corresponding entry to your Cargo.toml dependency list:

[dependencies]
cashify = "0.1"

Usage

The following example uses Serde JSON as strongly typed data structures. Instead of manually specifying rates, you can obtain them from an API, like Exchange Rates API.

use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use serde_json::Result;
use cashify::{convert};

#[derive(Serialize, Deserialize)]
struct Rates<'a>{
    base: &'a str,
    rates: HashMap<&'a str, f64>
}

fn main() -> Result<()> {
      let data = r#"{
          "base": "EUR",
          "rates": {
              "GBP": 0.92,
              "EUR": 1
          }
      }"#;
  
      let r: Rates = serde_json::from_str(data)?;

      println!("The result is: {}", convert(10.0, "EUR", "GBP", r.base, r.rates));
      Ok(())
}

Roadmap

The goal is to try and implement as much features from the original Cashify as possible.

  • convert Function
  • Constructor
  • Parsing

Related projects

License

MIT

Commit count: 6

cargo fmt