pub struct HandleMap<T> { /* private fields */ }
Expand description
HandleMap
is a collection type which can hold any type of value, and
offers a stable handle which can be used to retrieve it on insertion. These
handles offer methods for converting to and
from 64 bit integers, meaning they’re very easy to pass
over the FFI (they also implement IntoFfi
for the same purpose).
See the module level docs for more information.
Note: In FFI code, most usage of HandleMap
will be done through the
ConcurrentHandleMap
type, which is a thin wrapper around a
RwLock<HandleMap<Mutex<T>>>
.
Implementations§
Source§impl<T> HandleMap<T>
impl<T> HandleMap<T>
Sourcepub fn new_with_capacity(request: usize) -> Self
pub fn new_with_capacity(request: usize) -> Self
Allocate a new HandleMap
. Note that the actual capacity may be larger
than the requested value.
Panics if request
is greater than handle_map::MAX_CAPACITY
Sourcepub fn insert(&mut self, v: T) -> Handle
pub fn insert(&mut self, v: T) -> Handle
Insert an item into the map, and return a handle to it.
Sourcepub fn delete(&mut self, h: Handle) -> Result<(), HandleError>
pub fn delete(&mut self, h: Handle) -> Result<(), HandleError>
Delete an item from the HandleMap.
Sourcepub fn remove(&mut self, h: Handle) -> Result<T, HandleError>
pub fn remove(&mut self, h: Handle) -> Result<T, HandleError>
Remove an item from the HandleMap, returning the old value.
Sourcepub fn get(&self, h: Handle) -> Result<&T, HandleError>
pub fn get(&self, h: Handle) -> Result<&T, HandleError>
Get a reference to the item referenced by the handle, or return a
HandleError
describing the problem.
Sourcepub fn get_mut(&mut self, h: Handle) -> Result<&mut T, HandleError>
pub fn get_mut(&mut self, h: Handle) -> Result<&mut T, HandleError>
Get a mut reference to the item referenced by the handle, or return a
HandleError
describing the problem.