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
impl TryFromJsValue for ()impl TryFromJsValue for Stringimpl TryFromJsValue for boolimpl TryFromJsValue for charimpl TryFromJsValue for f32impl TryFromJsValue for f64impl TryFromJsValue for i128impl TryFromJsValue for i16impl TryFromJsValue for i32impl TryFromJsValue for i64impl TryFromJsValue for i8impl TryFromJsValue for isizeimpl TryFromJsValue for u128impl TryFromJsValue for u16impl TryFromJsValue for u32impl TryFromJsValue for u64impl TryFromJsValue for u8impl TryFromJsValue for usizeimpl<T> TryFromJsValue for JsNullable<T> where T: JsCast,impl<T> TryFromJsValue for JsOption<T> where T: JsCast,impl<T> TryFromJsValue for JsValue where T: JsCast,impl<T> TryFromJsValue for Null where T: JsCast,impl<T> TryFromJsValue for Undefined where T: JsCast,impl<T: JsCast> TryFromJsValue for Timpl<T: TryFromJsValue> TryFromJsValue for Option<T>impl<T: TryFromJsValue> TryFromJsValue for Vec<T>