Skip to main content

Crate wry_bindgen_core

Crate wry_bindgen_core 

Source
Expand description

§wry-bindgen-core

wry-bindgen-core is the minimal, stable API that wry-bindgen builds on. It exposes typed handles for talking to JavaScript: functions you can call, Rust values you can store and borrow back, and closures you can hand to JavaScript.

use wry_bindgen_core::with_runtime;

// Store a native Rust value and get back an opaque handle...
let handle = with_runtime(|rt| rt.insert_object(Counter::default()));

// ...then borrow it back by handle later.
with_runtime(|rt| {
    let mut counter = rt.object::<Counter>(handle);
    counter.tick();
});

§What it provides

  • JsFunction<F> — a typed handle to a JavaScript function. .call(args) runs the round-trip and returns the typed result.
  • Runtime and with_runtime — a typed object store: insert a Rust value for an ObjectHandle, borrow it back, or remove it.
  • LazyCell<T> / JsThreadLocal<T> — typed runtime-local JavaScript values, such as the global window.
  • CallbackKey<F> — registers a Rust closure with JavaScript, with Rust-owned, JS-owned, and JS-owned-once policies.
  • Clamped, BatchableResult, and RequireFlush — markers used when encoding arguments and return values.

Most of these are driven by the code wry-bindgen’s macro generates; the object store reached through with_runtime is the part you tend to use directly.

Structs§

CallbackKey
Clamped
A wrapper type around slices and vectors for binding Uint8ClampedArray.
DecodeError
DecodedData
EncodedData
JsClassMemberSpec
JsExportSpec
JsFunction
A typed JS function that resolves from the active runtime on first use.
JsFunctionSpec
JsModuleSpec
JsRef
LazyCell
A runtime-local accessor for lazily initialized JavaScript values.
ObjectHandle
RequireFlush
Runtime
A handle to the active runtime, scoped to a with_runtime call.
RustCallback
TypeDef

Enums§

JsClassMemberKind

Traits§

BatchableResult
BinaryDecode
BinaryEncode
EncodeTypeDef
JsRefEncode

Functions§

with_runtime
Run f with the active runtime.

Type Aliases§

JsThreadLocal
Backwards-compatible name used by generated thread_local_v2 bindings.