pub unsafe trait DowncastJS:
Sized
+ FromWasmAbi<Abi = u32>
+ RefFromWasmAbi<Abi = u32> {
// Required method
fn token() -> &'static DowncastToken;
// Provided methods
fn downcast_js(value: JsValue) -> Result<Self, JsValue> { ... }
fn downcast_js_ref(value: &JsValue) -> Option<Self::Anchor> { ... }
}
Expand description
Cast a Rust wrapper class that was generated by #[wasm_bindgen]
back to
the underlying Rust type.
This is a workaround for rustwasm/wasm-bindgen#2231 that is robust with respect to minification (something other solutions can’t handle).
§Safety
This assumes the wrapper class has a static __wbgd_downcast_symbol
method which returns the same DowncastToken
as
DowncastJS::token()
. Each trait implementation.
Users should use the custom derive rather than implement this manually.
Required Methods§
fn token() -> &'static DowncastToken
Provided Methods§
fn downcast_js(value: JsValue) -> Result<Self, JsValue>
fn downcast_js_ref(value: &JsValue) -> Option<Self::Anchor>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.