Created
April 6, 2021 01:02
-
-
Save tiffany352/622be553bf72da1afd73a887a3f6d3e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rink_core::ast::Defs; | |
// In real usage this should get cached and have a user agent set. | |
let currency_json = reqwest::get("https://rinkcalc.app/data/currency.json") | |
.await? | |
.text() | |
.await?; | |
// JSON is in serde format for Defs. | |
let mut live_defs = serde_json::from_str::<Defs>(¤cy_json)?; | |
let mut base_defs = gnu_units::parse_str(CURRENCY_FILE)?; | |
// Merge them together so that dependency resolution can take effect. | |
let mut defs = vec![]; | |
defs.append(&mut base_defs.defs); | |
defs.append(&mut live_defs.defs); | |
// Assuming you already have a context object from somewhere else to use. | |
let mut ctx: rink_core::Context = ...; | |
ctx.load(ast::Defs { defs }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment