pub struct ObjectStore<T> { /* private fields */ }
Expand description
A storage allowing references to objects that aren’t Send
or Sync
. The
references (ObjectRef
s) can be held in other threads, even if T
isn’t
Send
or Sync
, because in such a case, to access the object, you’ll still
need to be on the thread owning the ObjectStore
.
ObjectStore::clean
should be called once in a while to drop any unused
objects, or else ObjectStore::remove
should be called on objects when
dropping them.
Implementations§
Source§impl<T> ObjectStore<T>
impl<T> ObjectStore<T>
Sourcepub fn get(&self, obj_ref: &ObjectRef<T>) -> &T
pub fn get(&self, obj_ref: &ObjectRef<T>) -> &T
Returns a reference to the object referred to by obj_ref
.
§Panics
Panics if the reference doesn’t belong to this store.
Sourcepub fn get_mut(&mut self, obj_ref: &ObjectRef<T>) -> &mut T
pub fn get_mut(&mut self, obj_ref: &ObjectRef<T>) -> &mut T
Returns a mutable reference to the object referred to by obj_ref
.
§Panics
Panics if the reference doesn’t belong to this store.
pub fn insert(&mut self, data: T) -> ObjectRef<T>
Sourcepub fn remove(&mut self, obj_ref: ObjectRef<T>) -> Option<T>
pub fn remove(&mut self, obj_ref: ObjectRef<T>) -> Option<T>
Remove an object reference from the object store. If the reference count is then zero, the stored object is dropped and returned. If there are still any other active references, None is returned.
§Panics
Panics if the reference doesn’t belong to this store.