Trait workflow_wasm::convert::TryCastFromJs

source ·
pub trait TryCastFromJs
where Self: CastFromJs + RefFromWasmAbi<Abi = u32> + LongRefFromWasmAbi<Abi = u32> + Clone,
{ type Error: Display + From<Error>; // Required method fn try_cast_from( value: impl AsRef<JsValue>, ) -> Result<Cast<Self>, Self::Error>; // Provided methods fn try_owned_from(value: impl AsRef<JsValue>) -> Result<Self, Self::Error> { ... } fn resolve( js: impl AsRef<JsValue>, create: impl FnOnce() -> Result<Self, Self::Error>, ) -> Result<Cast<Self>, Self::Error> { ... } fn resolve_cast( js: impl AsRef<JsValue>, create: impl FnOnce() -> Result<Cast<Self>, Self::Error>, ) -> Result<Cast<Self>, Self::Error> { ... } }
Expand description

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.

Required Associated Types§

Required Methods§

source

fn try_cast_from(value: impl AsRef<JsValue>) -> Result<Cast<Self>, Self::Error>

Try to cast a JsValue into a Rust object. This should be user-defined function that attempts to cast a JsValue into a Rust object or interpret a source data and create a temporary struct owned by by the Cast.

Provided Methods§

source

fn try_owned_from(value: impl AsRef<JsValue>) -> Result<Self, Self::Error>

Perform a user cast and consume the Cast container. This function will return a temporary user-created object created during [try_cast_from] or a clone of the casted reference.

source

fn resolve( js: impl AsRef<JsValue>, create: impl FnOnce() -> Result<Self, Self::Error>, ) -> Result<Cast<Self>, Self::Error>

Try to cast a JsValue into a Rust object, in cast of failure invoke a user-supplied closure that can try to create an instance of the object based on the supplied JsValue.

source

fn resolve_cast( js: impl AsRef<JsValue>, create: impl FnOnce() -> Result<Cast<Self>, Self::Error>, ) -> Result<Cast<Self>, Self::Error>

Try to cast a JsValue into a Rust object, in cast of failure invoke a user-supplied closure that can try to create an instance of the object based on the supplied JsValue. Unlike the [resolve] function, this function expects create closure to return a Cast. This is useful when routing the creation of the object to another function that is capable of creating a compatible Cast wrapper.

Object Safety§

This trait is not object safe.

Implementors§