wasm_bindgen_futures - Rust (original) (raw)
Crate wasm_bindgen_futures
Expand description
Converting between JavaScript Promise
s to Rust Future
s.
This crate provides a bridge for working with JavaScript Promise
types as a Rust Future
, and similarly contains utilities to turn a rust Future
into a JavaScript Promise
. This can be useful when working with asynchronous or otherwise blocking work in Rust (wasm), and provides the ability to interoperate with JavaScript events and JavaScript I/O primitives.
There are three main interfaces in this crate currently:
- JsFuture
A type that is constructed with aPromise
and can then be used as aFuture<Output = Result<JsValue, JsValue>>
. This Rust future will resolve or reject with the value coming out of thePromise
. - future_to_promise
Converts a RustFuture<Output = Result<JsValue, JsValue>>
into a JavaScriptPromise
. The future’s result will translate to either a resolved or rejectedPromise
in JavaScript. - spawn_local
Spawns aFuture<Output = ()>
on the current thread. This is the best way to run aFuture
in Rust without sending it to JavaScript.
These three items should provide enough of a bridge to interoperate the two systems and make sure that Rust/JavaScript can work together with asynchronous and I/O work.
- stream
futures-core-03-stream
Converting JavaScriptAsyncIterator
s to RustStream
s. - A Rust
Future
backed by a JavaScriptPromise
. - Converts a Rust
Future
into a JavaScriptPromise
. - Runs a Rust
Future
on the current thread. - A list of all the attributes can be found here: https://rustwasm.github.io/docs/wasm-bindgen/reference/attributes/index.html