Crates.io | cashify |
lib.rs | cashify |
version | 0.1.1 |
source | src |
created_at | 2020-06-02 08:21:02.123176 |
updated_at | 2020-06-02 08:28:37.971564 |
description | Lightweight currency conversion library. |
homepage | https://github.com/xxczaki/cashify-rs |
repository | https://github.com/xxczaki/cashify-rs |
max_upload_size | |
id | 249167 |
size | 8,331 |
Lightweight currency conversion library.
This Rust crate is a port of the Cashify npm package from the same author. API is not the same.
Simply add the corresponding entry to your Cargo.toml
dependency list:
[dependencies]
cashify = "0.1"
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(())
}
The goal is to try and implement as much features from the original Cashify as possible.
convert
FunctionMIT