diff options
author | Nadrieril | 2020-05-29 22:22:30 +0100 |
---|---|---|
committer | Nadrieril | 2020-05-30 13:56:22 +0100 |
commit | 4aab03c67869ff4ecc473794f62e35e4565a01d6 (patch) | |
tree | dfc09be677e226be03ef992d05d42b4d3a043751 /dhall/src/semantics/resolve | |
parent | aaba9f7a1a6119443aa6a569e451e0e549e5bb37 (diff) |
Make reqwest build on wasm
Diffstat (limited to 'dhall/src/semantics/resolve')
-rw-r--r-- | dhall/src/semantics/resolve/resolve.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs index 3b72b9e..fb770db 100644 --- a/dhall/src/semantics/resolve/resolve.rs +++ b/dhall/src/semantics/resolve/resolve.rs @@ -159,9 +159,7 @@ impl ImportLocation { fn fetch_text(self) -> Result<String, Error> { Ok(match self { ImportLocation::Local(path) => std::fs::read_to_string(&path)?, - ImportLocation::Remote(url) => { - reqwest::blocking::get(url).unwrap().text().unwrap() - } + ImportLocation::Remote(url) => download_http_text(url)?, ImportLocation::Env(var_name) => match env::var(var_name) { Ok(val) => val, Err(_) => return Err(ImportError::MissingEnvVar.into()), @@ -197,6 +195,18 @@ fn mkexpr(kind: UnspannedExpr) -> Expr { Expr::new(kind, Span::Artificial) } +// TODO: error handling +#[cfg(not(target_arch = "wasm32"))] +pub(crate) fn download_http_text(url: Url) -> Result<String, Error> { + Ok(reqwest::blocking::get(url).unwrap().text().unwrap()) +} +#[cfg(target_arch = "wasm32")] +pub(crate) fn download_http_text(url: Url) -> Result<String, Error> { + blocking::block_on(async { + Ok(reqwest::get(url).await.unwrap().text().await.unwrap()) + }) +} + fn make_aslocation_uniontype() -> Expr { let text_type = mkexpr(ExprKind::Builtin(Builtin::Text)); let mut union = BTreeMap::default(); |