Struct dynstore::ObjectStore
source · [−]pub struct ObjectStore<Tag = Send> { /* private fields */ }
Expand description
Stores arbitrary objects as long as they implement Castable
and tag::Satisfies<Tag>
for
the choice of Tag
.
See the module documentation for more info.
Implementations
sourceimpl ObjectStore<ThreadLocal>
impl ObjectStore<ThreadLocal>
sourcepub fn new_thread_local() -> Self
pub fn new_thread_local() -> Self
Instantiates a new ObjectStore
object that can store objects which are !Send
and
!Sync
.
sourceimpl ObjectStore<Send>
impl ObjectStore<Send>
sourcepub fn new_send() -> Self
pub fn new_send() -> Self
Instantiates a new ObjectStore
object that can store objects which are Send
but
!Sync
.
sourceimpl ObjectStore<SendSync>
impl ObjectStore<SendSync>
sourcepub fn new_sync() -> Self
pub fn new_sync() -> Self
Instantiates a new ObjectStore
object that can store objects which are Send
and Sync
.
sourceimpl<Tag> ObjectStore<Tag>
impl<Tag> ObjectStore<Tag>
sourcepub fn new() -> Self
pub fn new() -> Self
Instantiates a new ObjectStore
object.
sourcepub fn push<T>(&mut self, buffer_ix: u32, item: T) -> Handle<T> where
T: Castable + Satisfies<Tag>,
pub fn push<T>(&mut self, buffer_ix: u32, item: T) -> Handle<T> where
T: Castable + Satisfies<Tag>,
Pushes a new object to the given buffer and returns a handle for it. Any u32
can be
chosen as the buffer_ix
but bear in mind that a large choice of index will cause a large
allocation to happen if smaller buffer indexes have not yet been used.
sourcepub fn find<'a, T>(
&'a self,
buffer_ix: u32
) -> impl Iterator<Item = Handle<T>> + 'a where
T: ?Sized + 'static,
pub fn find<'a, T>(
&'a self,
buffer_ix: u32
) -> impl Iterator<Item = Handle<T>> + 'a where
T: ?Sized + 'static,
Iterates over handles for all stored objects in the given buffer that are castable to the requested type. This is a fast operation implemented as a range lookup in a BTreeSet.
sourcepub fn find_dynamic<'a>(
&'a self,
buffer_ix: u32,
type_id: TypeId
) -> impl Iterator<Item = DynamicHandle> + 'a
pub fn find_dynamic<'a>(
&'a self,
buffer_ix: u32,
type_id: TypeId
) -> impl Iterator<Item = DynamicHandle> + 'a
Iterates over dynamic handles for all stored objects in the given buffer that are castable to the requested type. This is a fast operation implemented as a range lookup in a BTreeSet.
sourcepub fn cast_from_dynamic<T>(&self, handle: DynamicHandle) -> Option<Handle<T>> where
T: ?Sized + 'static,
pub fn cast_from_dynamic<T>(&self, handle: DynamicHandle) -> Option<Handle<T>> where
T: ?Sized + 'static,
Casts an untyped DynamicHandle
up to a typed Handle
. Panics if the input handle is not
associated with this ObjectStore
. Returns None
if the object that the handle
points to is not castable to the requested type.
sourcepub fn cast_to_dynamic<T>(&self, handle: Handle<T>) -> DynamicHandle where
T: ?Sized,
pub fn cast_to_dynamic<T>(&self, handle: Handle<T>) -> DynamicHandle where
T: ?Sized,
Casts a handle down to an untyped DynamicHandle. Panics if the input handle is not
associated with this ObjectStore
.
sourcepub fn cast<T, U>(&self, handle: Handle<T>) -> Option<Handle<U>> where
T: ?Sized + 'static,
U: ?Sized + 'static,
pub fn cast<T, U>(&self, handle: Handle<T>) -> Option<Handle<U>> where
T: ?Sized + 'static,
U: ?Sized + 'static,
Casts a handle to a different type. Panics if the input handle is not associated with this
ObjectStore
. Returns None
if the concrete type pointed to by the input handle is
not castable to U
.
sourcepub fn get<T>(&self, handle: Handle<T>) -> &T where
T: ?Sized + 'static,
pub fn get<T>(&self, handle: Handle<T>) -> &T where
T: ?Sized + 'static,
Accesses an object reference through a handle. Panics if the handle is not associated
with this ObjectStore
. This is very cheap: about as cheap as a bounds-checked index into
an array.
sourcepub fn get_mut<T>(&mut self, handle: Handle<T>) -> &mut T where
T: ?Sized + 'static,
pub fn get_mut<T>(&mut self, handle: Handle<T>) -> &mut T where
T: ?Sized + 'static,
Accesses a mutable object reference through a handle. Panics if the handle is not
associated with this ObjectStore
. This is very cheap: about as cheap as a bounds-checked
index into an array.
sourcepub fn get_type_id<T>(&self, handle: Handle<T>) -> TypeId where
T: ?Sized,
pub fn get_type_id<T>(&self, handle: Handle<T>) -> TypeId where
T: ?Sized,
Returns the TypeId
of the concrete type stored at the given handle. The returned type
id will not match T
if T
is a trait object type. Panics if the input handle is not
associated with this ObjectStore
.
sourcepub fn get_type_id_dynamic(&self, handle: DynamicHandle) -> TypeId
pub fn get_type_id_dynamic(&self, handle: DynamicHandle) -> TypeId
Returns the TypeId
of the concrete type stored at the given handle. Panics if the input
handle is not associated with this ObjectStore
.
sourcepub fn get_type_name<T>(&self, handle: Handle<T>) -> &str where
T: ?Sized,
pub fn get_type_name<T>(&self, handle: Handle<T>) -> &str where
T: ?Sized,
Gets the name of the type stored at the given handle. Panics if the input handle is not
associated with this ObjectStore
.
sourcepub fn get_type_name_dynamic(&self, handle: DynamicHandle) -> &str
pub fn get_type_name_dynamic(&self, handle: DynamicHandle) -> &str
Gets the name of the type stored at the given dynamic handle. Panics if the input handle is
not associated with this ObjectStore
.
Trait Implementations
impl<Tag> Send for ObjectStore<Tag> where
Tag: Send,
The object store as Send
if its tag is Send
because this ensures that all contained objects
are Send
.
impl<Tag> Sync for ObjectStore<Tag> where
Tag: Sync,
The object store as Sync
if its tag is Sync
because this ensures that all contained objects
are Sync
.
Auto Trait Implementations
impl<Tag> RefUnwindSafe for ObjectStore<Tag> where
Tag: RefUnwindSafe,
impl<Tag> Unpin for ObjectStore<Tag> where
Tag: Unpin,
impl<Tag> UnwindSafe for ObjectStore<Tag> where
Tag: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more