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§
- IWAS
M32Bindings Config - JavaScript configuration object for the workflow-rs WASM32 bindings runtime.
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.Castthen 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 CastFromJstrait is automatically implemented by deriving theCastFromJsderive macro. This trait provides functions for accessing Rust references from the WASM ABI.- Deref
- Used for immutable dereferencing operations, like
*v. - TryCast
From Js TryCastFromJstrait is meant to be implemented by the developer on any struct implementingCastFromJstrait. 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 - Inverse of
TryCastFromJs, allowing a source value (such as aJsValue) to be cast into a target Rust typeTthat implementsTryCastFromJs.
Functions§
- init_
wasm32_ bindings - Configuration for the WASM32 bindings runtime interface. @see {@link IWASM32BindingsConfig} @category General
- try_
clone_ from_ abi_ safe - Clone a Rust object out of a WASM ABI reference obtained from a
JsValue. - try_
clone_ from_ abi_ safe_ as_ option - Clone a Rust object out of a WASM ABI reference obtained from a
JsValue, returningNoneif the value isnullorundefined. - try_
copy_ from_ abi_ safe - Copy a Rust object out of a WASM ABI reference obtained from a
JsValue. - try_
copy_ from_ abi_ safe_ as_ option - Copy a Rust object out of a WASM ABI reference obtained from a
JsValue, returningNoneif the value isnullorundefined. - try_
long_ ref_ from_ abi_ safe - Create a long-lived reference to a Rust object from a WASM ABI obtained from a
JsValue. - 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
nullorundefined, otherwise attempts to cast the object. - try_
ref_ mut_ from_ abi_ safe - Create a mutable reference to a Rust object from a WASM ABI obtained from a
JsValue. - try_
ref_ mut_ from_ abi_ safe_ as_ option - Create a mutable reference to a Rust object from a WASM ABI obtained from a
JsValue, returningNoneif the value isnullorundefined. - validate_
class_ names - Returns whether runtime validation of WASM class names is currently enabled.
Derive Macros§
- Cast
From Js - Derives
CastFromJsfor a type, generating the implementation that safely casts aJsValuereference back into the corresponding Rust type viaworkflow-wasm’s conversion helpers.