pub struct Table<V> { /* private fields */ }
Expand description
This is a table for generating unique u32 identifiers for each element in a dynamically-changing set of resources.
This is inspired by the Table
type in
wasi-common and serves the same
purpose: allow opaque resources and their lifetimes to be managed across an interface boundary, analogous to
how file handles work across the user-kernel boundary.
Implementations§
Source§impl<V> Table<V>
impl<V> Table<V>
Sourcepub fn push(&mut self, value: V) -> Result<u32, ()>
pub fn push(&mut self, value: V) -> Result<u32, ()>
Add the specified resource to this table.
If the table is full (i.e. there already are self.capacity
resources inside), this returns Err(())
.
Otherwise, a new, unique identifier is allocated for the resource and returned.
This function will attempt to avoid reusing recently closed identifiers, but after 2^32 calls to this function they will start repeating.
Sourcepub fn get(&self, key: u32) -> Option<&V>
pub fn get(&self, key: u32) -> Option<&V>
Get a reference to the resource identified by the specified key
, if it exists.