pub struct ResourceOwn { /* private fields */ }
Expand description
Represents a resource that is owned by the host.
Implementations§
Source§impl ResourceOwn
impl ResourceOwn
Sourcepub fn new<T: 'static + Send + Sync + Sized>(
ctx: impl AsContextMut,
value: T,
ty: ResourceType,
) -> Result<Self>
pub fn new<T: 'static + Send + Sync + Sized>( ctx: impl AsContextMut, value: T, ty: ResourceType, ) -> Result<Self>
Creates a new resource for the given value. The value must match the resource type, which must be a host resource type.
Sourcepub fn borrow(&self, ctx: impl AsContextMut) -> Result<ResourceBorrow>
pub fn borrow(&self, ctx: impl AsContextMut) -> Result<ResourceBorrow>
Creates a borrow of this owned resource. The resulting borrow must be manually released via ResourceBorrow::drop
afterward.
Sourcepub fn rep<'a, T: 'static + Send + Sync, S, E: WasmEngine>(
&self,
ctx: &'a StoreContext<'_, S, E>,
) -> Result<&'a T>
pub fn rep<'a, T: 'static + Send + Sync, S, E: WasmEngine>( &self, ctx: &'a StoreContext<'_, S, E>, ) -> Result<&'a T>
Gets the internal representation of this resource. Fails if this is not a host resource, or if the resource was already dropped.
Sourcepub fn rep_mut<'a, T: 'static + Send + Sync, S, E: WasmEngine>(
&self,
ctx: &'a mut StoreContextMut<'_, S, E>,
) -> Result<&'a mut T>
pub fn rep_mut<'a, T: 'static + Send + Sync, S, E: WasmEngine>( &self, ctx: &'a mut StoreContextMut<'_, S, E>, ) -> Result<&'a mut T>
Gets the internal mut representation of this resource. Fails if this is not a host resource, or if the resource was already dropped.
Sourcepub fn ty(&self) -> ResourceType
pub fn ty(&self) -> ResourceType
Gets the type of this value.
Sourcepub fn take<T: 'static + Send + Sync>(
&self,
ctx: impl AsContextMut,
) -> Result<()>
pub fn take<T: 'static + Send + Sync>( &self, ctx: impl AsContextMut, ) -> Result<()>
Removes this resource from the context without invoking the destructor, and returns the value. Fails if this is not a host resource, or if the resource is borrowed.
Sourcepub fn drop(&self, ctx: impl AsContextMut) -> Result<()>
pub fn drop(&self, ctx: impl AsContextMut) -> Result<()>
Drops this resource and invokes the destructor, removing it from the context. Fails if the resource is borrowed or already destroyed.
Trait Implementations§
Source§impl Clone for ResourceOwn
impl Clone for ResourceOwn
Source§fn clone(&self) -> ResourceOwn
fn clone(&self) -> ResourceOwn
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more