Skip to content

Lightweight currency conversion library, written in Rust.

License

Notifications You must be signed in to change notification settings

xxczaki/cashify-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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