2 releases
0.1.1 | Jun 2, 2020 |
---|---|
0.1.0 | Jun 2, 2020 |
#285 in Finance
8KB
124 lines
Cashify 💸
Lightweight currency conversion library.
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