Struct wasi_common::table::Table
source · pub struct Table(/* private fields */);
Expand description
The Table
type is designed to map u32 handles to resources. The table is now part of the
public interface to a WasiCtx
- it is reference counted so that it can be shared beyond a
WasiCtx
with other WASI proposals (e.g. wasi-crypto
and wasi-nn
) to manage their
resources. Elements in the Table
are Any
typed.
The Table
type is intended to model how the Interface Types concept of Resources is shaping
up. Right now it is just an approximation.
Implementations§
source§impl Table
impl Table
sourcepub fn insert_at<T: Any + Send + Sync>(&self, key: u32, a: Arc<T>)
pub fn insert_at<T: Any + Send + Sync>(&self, key: u32, a: Arc<T>)
Insert a resource at a certain index.
sourcepub fn push<T: Any + Send + Sync>(&self, a: Arc<T>) -> Result<u32, Error>
pub fn push<T: Any + Send + Sync>(&self, a: Arc<T>) -> Result<u32, Error>
Insert a resource at the next available index.
sourcepub fn contains_key(&self, key: u32) -> bool
pub fn contains_key(&self, key: u32) -> bool
Check if the table has a resource at the given index.
sourcepub fn is<T: Any + Sized>(&self, key: u32) -> bool
pub fn is<T: Any + Sized>(&self, key: u32) -> bool
Check if the resource at a given index can be downcast to a given type. Note: this will always fail if the resource is already borrowed.
sourcepub fn get<T: Any + Send + Sync + Sized>(
&self,
key: u32
) -> Result<Arc<T>, Error>
pub fn get<T: Any + Send + Sync + Sized>( &self, key: u32 ) -> Result<Arc<T>, Error>
Get an Arc reference to a resource of a given type at a given index. Multiple immutable references can be borrowed at any given time.
sourcepub fn get_mut<T: Any>(&mut self, key: u32) -> Result<&mut T, Error>
pub fn get_mut<T: Any>(&mut self, key: u32) -> Result<&mut T, Error>
Get a mutable reference to a resource of a given type at a given index. Only one such reference can be borrowed at any given time.