summaryrefslogtreecommitdiff
path: root/dhall/src/semantics/resolve/resolve.rs
diff options
context:
space:
mode:
authorNadrieril2020-05-29 22:22:30 +0100
committerNadrieril2020-05-30 13:56:22 +0100
commit4aab03c67869ff4ecc473794f62e35e4565a01d6 (patch)
treedfc09be677e226be03ef992d05d42b4d3a043751 /dhall/src/semantics/resolve/resolve.rs
parentaaba9f7a1a6119443aa6a569e451e0e549e5bb37 (diff)
Make reqwest build on wasm
Diffstat (limited to 'dhall/src/semantics/resolve/resolve.rs')
-rw-r--r--dhall/src/semantics/resolve/resolve.rs16
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();