from_js_ref
Runtime traits for converting between JS-imported reference types and Rust-exported wasm-bindgen types.
This crate is the companion to wasm_refgen, which generates implementations of these traits via a proc-macro.
Traits
FromJsRef
JsDeref
A convenience trait blanket-implemented for all T::JsRef types:
let wasm_foo: WasmFoo = js_foo.js_deref;
Usage
You typically don't implement these traits by hand. Instead, use
#[wasm_refgen(js_ref = JsFoo)] on your impl block, which generates
the FromJsRef implementation automatically.
use FromJsRef;
// From a typed reference (infallible)
let foo: WasmFoo = from_js_ref;
// From a raw JsValue (fallible, duck-type validated)
let foo: = try_from_js_value;
[!WARNING] Do not use
dyn_into::<JsFoo>()ordyn_ref::<JsFoo>()withwasm_refgen-generated types. These rely oninstanceof, which targets the Rust identifier name rather than the JS class name. UseFromJsRef::try_from_js_valueinstead.
License
Apache-2.0