From fc81d8f6d39a566976ee27c2811aaa08f285f827 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 21 Mar 2018 12:37:10 -0700 Subject: [PATCH] Add From/Into JsValue for imported types --- crates/wasm-bindgen-macro/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/wasm-bindgen-macro/src/lib.rs b/crates/wasm-bindgen-macro/src/lib.rs index e9eb4a3a..410552f3 100755 --- a/crates/wasm-bindgen-macro/src/lib.rs +++ b/crates/wasm-bindgen-macro/src/lib.rs @@ -369,6 +369,18 @@ impl ToTokens for ast::ImportType { self.obj.to_js_ref() } } + + impl From<::wasm_bindgen::JsValue> for #name { + fn from(obj: ::wasm_bindgen::JsValue) -> #name { + #name { obj } + } + } + + impl From<#name> for ::wasm_bindgen::JsValue { + fn from(obj: #name) -> ::wasm_bindgen::JsValue { + obj.obj + } + } }).to_tokens(tokens); } }