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>

source

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.

source

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.

source

pub fn as_raw(handle: &Handle<T>) -> i32

Returns the raw underlying handle value for this handle.

This typically isn’t necessary to interact with, but can be useful when interacting with raw ABI bindings.

source

pub unsafe fn from_raw(val: i32) -> Handle<T>

Unsafely assumes that the given integer descriptor is a handle for T.

This is unsafe because no validation is performed to ensure that val is actually a valid descriptor for T.

Trait Implementations§

source§

impl<T: HandleType> Clone for Handle<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: HandleType> Debug for Handle<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: LocalHandle> Deref for Handle<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<T: HandleType> Drop for Handle<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T: LocalHandle> From<T> for Handle<T>

source§

fn from(val: T) -> Handle<T>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Handle<T>where T: RefUnwindSafe,

§

impl<T> Send for Handle<T>where T: Send,

§

impl<T> Sync for Handle<T>where T: Sync,

§

impl<T> Unpin for Handle<T>where T: Unpin,

§

impl<T> UnwindSafe for Handle<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.