Struct wai_bindgen_rust::Handle
source · pub struct Handle<T: HandleType> { /* private fields */ }
Expand description
A type for handles to resources that appear in exported functions.
This type is used as Handle<T>
for argument types and return values of
exported functions when exposing a Rust-defined resource. A Handle<T>
represents an owned reference count on the interface-types-managed resource.
It’s similar to an Rc<T>
in Rust. Internally a Handle<T>
can provide
access to &T
when T
is defined in the current module.
Implementations§
source§impl<T: HandleType> Handle<T>
impl<T: HandleType> Handle<T>
sourcepub fn new(val: T) -> Handle<T>where
T: LocalHandle,
pub fn new(val: T) -> Handle<T>where T: LocalHandle,
Creates a new handle around the specified value.
Note that the lifetime of T
will afterwards be managed by the
interface types runtime. The host may hold references to T
that wasm
isn’t necessarily aware of, preventing its destruction. Nevertheless
though the Drop for T
implementation will still be run when there are
no more references to T
.
sourcepub fn into_raw(handle: Handle<T>) -> i32
pub fn into_raw(handle: Handle<T>) -> i32
Consumes a handle and returns the underlying raw wasm i32 descriptor.
Note that this, if used improperly, will leak the resource T
. This
generally should be avoided unless you’re calling raw ABI bindings and
managing the lifetime manually.