Skip to content

Commit

Permalink
wasm: avoid dependency on serde-serialize feature (#1337)
Browse files Browse the repository at this point in the history
Using this feature makes dependency cycles much more likely.
  • Loading branch information
KamilaBorowska committed Sep 27, 2021
1 parent 2767071 commit cfa301c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ winreg = "0.7"

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3.45"
wasm-bindgen = { version = "0.2.68", features = ["serde-serialize"] }
serde_json = "1.0"
wasm-bindgen = "0.2.68"
wasm-bindgen-futures = "0.4.18"

[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
Expand All @@ -169,6 +170,7 @@ features = [
]

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen = { version = "0.2.68", features = ["serde-serialize"] }
wasm-bindgen-test = "0.3"

[[example]]
Expand Down
13 changes: 7 additions & 6 deletions src/wasm/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use http::{HeaderMap, Method};
use js_sys::Promise;
use js_sys::{Promise, JSON};
use std::{fmt, future::Future, sync::Arc};
use url::Url;
use wasm_bindgen::prelude::{wasm_bindgen, UnwrapThrowExt as _};
Expand Down Expand Up @@ -238,11 +238,12 @@ async fn fetch(req: Request) -> crate::Result<Response> {

for item in js_iter {
let item = item.expect_throw("headers iterator doesn't throw");
let v: Vec<String> = item.into_serde().expect_throw("headers into_serde");
resp = resp.header(
v.get(0).expect_throw("headers name"),
v.get(1).expect_throw("headers value"),
);
let serialized_headers: String = JSON::stringify(&item)
.expect_throw("serialized headers")
.into();
let [name, value]: [String; 2] = serde_json::from_str(&serialized_headers)
.expect_throw("deserializable serialized headers");
resp = resp.header(name, value);
}

resp.body(js_resp)
Expand Down

0 comments on commit cfa301c

Please sign in to comment.