Skip to content

Commit

Permalink
Remove serde feature from wasm-bindgen
Browse files Browse the repository at this point in the history
According to this issue
tkaitchuck/aHash#95
  • Loading branch information
AlexeyVavilin committed Jul 29, 2021
1 parent 9191dcf commit 92c3deb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ton_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ tokio-tungstenite = { version = "0.11.0", features = ["tls"], optional = true }

# optional for wasm
js-sys = { version = "0.3.50", optional = true }
wasm-bindgen = { version = "0.2.73", features = ["serde-serialize"], optional = true }
wasm-bindgen = { version = "0.2.73", optional = true }
wasm-bindgen-futures = { version = "0.4.15", optional = true }

[dependencies.web-sys]
Expand Down
17 changes: 6 additions & 11 deletions ton_client/src/client/wasm_client_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@ use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use web_sys::{Event, MessageEvent, Request, RequestInit, Response, Window};
use js_sys::JSON;

fn js_value_to_value(js_value: JsValue) -> ClientResult<serde_json::Value> {
js_value
.into_serde::<serde_json::Value>()
.map_err(|_| Error::cannot_convert_jsvalue_to_json(js_value))
}

fn js_value_to_string(js_value: JsValue) -> String {
fn js_error_to_string(js_value: JsValue) -> String {
if let Ok(txt) = js_value.clone().dyn_into::<js_sys::Error>() {
String::from(txt.message())
} else {
js_value_to_value(js_value)
.map(|val| format!("{:#}", val))
JSON::stringify(&js_value)
.map(|val| String::from(val))
.unwrap_or("Unserializable value".to_owned())
}
}
Expand Down Expand Up @@ -214,7 +209,7 @@ impl ClientEnv {
log::trace!("Websocket send: {}", string);
let result = ws
.send_with_str(&string)
.map_err(|err| Error::websocket_send_error(js_value_to_string(err)));
.map_err(|err| Error::websocket_send_error(js_error_to_string(err)));
let _ = sender.send(result);
}
let _ = ws.close();
Expand Down Expand Up @@ -285,7 +280,7 @@ impl ClientEnv {
let mut resp_future = JsFuture::from(window.fetch_with_request(&request))
.map(|result| match result {
Ok(result) => Ok(result),
Err(err) => Err(Error::http_request_send_error(js_value_to_string(err))),
Err(err) => Err(Error::http_request_send_error(js_error_to_string(err))),
});

let resp_result = match timeout_ms {
Expand Down

0 comments on commit 92c3deb

Please sign in to comment.