Skip to content

Instantly share code, notes, and snippets.

@tiffany352
Created April 6, 2021 01:02
Show Gist options
  • Save tiffany352/622be553bf72da1afd73a887a3f6d3e7 to your computer and use it in GitHub Desktop.
Save tiffany352/622be553bf72da1afd73a887a3f6d3e7 to your computer and use it in GitHub Desktop.
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>(&currency_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