alef 0.91.0

Opinionated polyglot binding generator for Rust libraries
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/// Wrapper that bridges a foreign JavaScript object to a Rust trait.
///
/// Holds the JS object via a persistent napi reference (`ObjectRef`) rather than
/// a borrowed `Object` transmuted to `'static`. The reference is released in
/// `dispose()` (and defensively in `Drop`) so the outstanding handle no longer
/// pins the libuv event loop, letting Node/worker threads exit cleanly.
pub struct {{ wrapper_name }} {
    env: napi::sys::napi_env,
    /// Thread `new()` ran on — always the JS thread. See the sync fast/slow split
    /// (`gen_sync_method_body`) and the drop-hazard guard (`release_ref`).
    js_thread: std::thread::ThreadId,
    obj_ref: std::sync::Mutex<Option<napi::bindgen_prelude::ObjectRef<false>>>,
    cached_name: String,
{% for f in extra_fields %}
    {{ f.name }}: {{ f.ty }},
{% endfor %}
}