Trait TryFromJsValue

pub trait TryFromJsValue: Sized

TryFromJsValue is a trait for converting a JavaScript value (JsValue) into a Rust type. It is used by the wasm_bindgen proc-macro to allow conversion to user types.

The semantics of this trait for various types are designed to provide a runtime analog of the static semantics implemented by the IntoWasmAbi function bindgen, with the exception that conversions are constrained to not cast invalid types.

For example, where the Wasm static semantics will permit foo(x: i32) when passed from JS foo("5") to treat that as foo(5), this trait will instead throw. Apart from these reduced type conversion cases, behaviours should otherwise match the static semantics.

Types implementing this trait must specify their conversion logic from JsValue to the Rust type, handling any potential errors that may occur during the conversion process.

⚠️ Unstable

This is part of the internal convert module, no stability guarantees are provided. Use at your own risk. See its documentation for more details.

Required Methods

fn try_from_js_value_ref(value: &JsValue) -> Option<Self>

Performs the conversion.

Provided Methods

fn try_from_js_value(value: JsValue) -> Result<Self, JsValue>

Performs the conversion.

Implementors