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§
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 providesCast::as_ref()
to obtain the internally held reference andCast::into_owned()
where the latter will consume the value or clone the reference.
Traits§
- Borrow
- A trait for borrowing data.
- Cast
From Js CastFromJs
trait is automatically implemented by deriving theCastFromJs
derive macro. This trait provides functions for accessing Rust references from the WASM ABI.- Deref
- Used for immutable dereferencing operations, like
*v
. - TryCast
From Js TryCastFromJs
trait is meant to be implemented by the developer on any struct implementingCastFromJs
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 theCast
.- TryCast
JsInto
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
orundefined
, otherwise attempts to cast the object. - try_
ref_ mut_ from_ abi_ safe - try_
ref_ mut_ from_ abi_ safe_ as_ option - validate_
class_ names