Module convert

Source
Expand description

WASM bindgen casting and utility functions.

This module provides a CastFromJs trait and derive macro that allows for easy casting of JavaScript objects into Rust. The secondary goal of this module is to provide the ability to dynamically interpret user-supplied JavaScript data that instead of a Rust object may container other data that can be used (interpreted) to create a Rust object.

To accommodate this a TryCastFromJs trait is provided where user needs to implement try_cast_from function that can attempt to cast a JsValue into a Rust object or interpret the source data and create a temporary struct owned by by the Cast enum.

Structs§

IWASM32BindingsConfig

Enums§

Cast
A wrapper for a Rust object that can be either a reference or a value. This wrapper is used to carry a Rust (WASM ABI) reference provided by wasm_bindgen, but at the same time allows creation of a temporary object that can be created by interpreting the source user-supplied data. Cast then provides Cast::as_ref() to obtain the internally held reference and Cast::into_owned() where the latter will consume the value or clone the reference.

Traits§

Borrow
A trait for borrowing data.
CastFromJs
CastFromJs trait is automatically implemented by deriving the CastFromJs derive macro. This trait provides functions for accessing Rust references from the WASM ABI.
Deref
Used for immutable dereferencing operations, like *v.
TryCastFromJs
TryCastFromJs trait is meant to be implemented by the developer on any struct implementing CastFromJs trait. This trait provides a way to attempt to cast a JsValue into a Rust object or interpret the source data and create a temporary struct owned by by the Cast.
TryCastJsInto

Functions§

init_wasm32_bindings
Configuration for the WASM32 bindings runtime interface. @see {@link IWASM32BindingsConfig} @category General
try_clone_from_abi_safe
try_clone_from_abi_safe_as_option
try_copy_from_abi_safe
try_copy_from_abi_safe_as_option
try_long_ref_from_abi_safe
try_ref_from_abi_safe
Create a reference to a Rust object from a WASM ABI.
try_ref_from_abi_safe_as_option
Create a reference to a Rust object from a WASM ABI. Returns None is the supplied value is null or undefined, otherwise attempts to cast the object.
try_ref_mut_from_abi_safe
try_ref_mut_from_abi_safe_as_option
validate_class_names

Derive Macros§

CastFromJs