Struct ObjectStore

Source
pub struct ObjectStore<T> { /* private fields */ }
Expand description

A storage allowing references to objects that aren’t Send or Sync. The references (ObjectRefs) 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>

Source

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.

Source

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.

Source

pub fn clean(&mut self)

Garbage-collects unused objects.

Source

pub fn insert(&mut self, data: T) -> ObjectRef<T>

Source

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.

Trait Implementations§

Source§

impl<T> Default for ObjectStore<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ObjectStore<T>

§

impl<T> RefUnwindSafe for ObjectStore<T>
where T: RefUnwindSafe,

§

impl<T> Send for ObjectStore<T>
where T: Send,

§

impl<T> Sync for ObjectStore<T>
where T: Sync,

§

impl<T> Unpin for ObjectStore<T>
where T: Unpin,

§

impl<T> UnwindSafe for ObjectStore<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.