Skip to main content

Module convert

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
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. 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
Inverse of TryCastFromJs, allowing a source value (such as a JsValue) to be cast into a target Rust type T that implements TryCastFromJs.

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, returning None if the value is null or undefined.
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, returning None if the value is null or undefined.
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 null or undefined, 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, returning None if the value is null or undefined.
validate_class_names
Returns whether runtime validation of WASM class names is currently enabled.

Derive Macros§

CastFromJs
Derives CastFromJs for a type, generating the implementation that safely casts a JsValue reference back into the corresponding Rust type via workflow-wasm’s conversion helpers.