Struct dynstore::UninitObjectStore
source · [−]pub struct UninitObjectStore<Tag = Send> { /* private fields */ }
Expand description
A partially initialized object store containing potentially uninitialized objects. Supports
reserving slots for data and provides handles. Does not allow access to any contained data
until the store is converted to an ObjectStore
using UninitObjectStore::try_init
. This
is only possible when every handle has been written to.
Implementations
sourceimpl UninitObjectStore<ThreadLocal>
impl UninitObjectStore<ThreadLocal>
sourcepub fn new_thread_local() -> Self
pub fn new_thread_local() -> Self
Instantiates a new UninitObjectStore
object that can store objects which are !Send
and
!Sync
.
sourceimpl UninitObjectStore<Send>
impl UninitObjectStore<Send>
sourcepub fn new_send() -> Self
pub fn new_send() -> Self
Instantiates a new UninitObjectStore
object that can store objects which are Send
but
!Sync
.
sourceimpl UninitObjectStore<SendSync>
impl UninitObjectStore<SendSync>
sourcepub fn new_sync() -> Self
pub fn new_sync() -> Self
Instantiates a new UninitObjectStore
object that can store objects which are Send
and Sync
.
sourceimpl<Tag> UninitObjectStore<Tag>
impl<Tag> UninitObjectStore<Tag>
sourcepub fn new() -> Self
pub fn new() -> Self
Instantiates a new UninitObjectStore
object.
sourcepub fn try_init(self) -> Result<ObjectStore<Tag>, UninitObjectStore<Tag>>
pub fn try_init(self) -> Result<ObjectStore<Tag>, UninitObjectStore<Tag>>
If every reserved handle has been written to, returns Ok
with an initialized
ObjectStore
. Otherwise, returns Err(self)
.
sourcepub fn iter_unwritten_handles<'a>(
&'a self
) -> impl Iterator<Item = (DynamicHandle, UninitObjectInfo)> + 'a
pub fn iter_unwritten_handles<'a>(
&'a self
) -> impl Iterator<Item = (DynamicHandle, UninitObjectInfo)> + 'a
Iterates over unwritten handles in this store. Intended mainly for diagnostics.
sourcepub fn count_unwritten_handles(&self) -> usize
pub fn count_unwritten_handles(&self) -> usize
Returns the number of objects in this store that are yet to be written.
sourcepub fn can_init(&self) -> bool
pub fn can_init(&self) -> bool
Returns true if a call to UninitObjectStore::try_init
will succeed.
sourcepub fn reserve<T>(&mut self, buffer_ix: u32) -> Handle<T> where
T: Castable + Satisfies<Tag>,
pub fn reserve<T>(&mut self, buffer_ix: u32) -> Handle<T> where
T: Castable + Satisfies<Tag>,
Pushes a reservation for 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. This
handle must later be written to with UninitObjectStore::write
, otherwise initializing
the store will panic.
sourcepub fn write<T>(&mut self, handle: Handle<T>, value: T) where
T: Sized,
pub fn write<T>(&mut self, handle: Handle<T>, value: T) where
T: Sized,
If the given handle has not already been written to, writes the given value to it. Otherwise, panics. Also panics if the handle is not associated with this object store.
sourcepub fn try_write<T>(&mut self, handle: Handle<T>, value: T) -> bool where
T: Sized,
pub fn try_write<T>(&mut self, handle: Handle<T>, value: T) -> bool where
T: Sized,
If the given handle has not already been written to, writes the given value to it and
returns true
. Otherwise, returns false
. Panics if the handle is not associated with
this object store.
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>,
Reserves a new object in 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 UninitObjectStore
. 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 UninitObjectStore
.
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
UninitObjectStore
. Returns None
if the concrete type pointed to by the input handle is
not castable to U
.
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 UninitObjectStore
.
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 UninitObjectStore
.
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 UninitObjectStore
.
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 UninitObjectStore
.
Trait Implementations
impl<Tag> Send for UninitObjectStore<Tag> where
Tag: Send,
An uninit object store as Send
as long as its tag is Send
because the tag ensures that all
stored objects are Send
.
impl<Tag> Sync for UninitObjectStore<Tag>
An uninit object store can be safely accessed from any thread regardless of its tag because objects inside it cannot be accessed while it is uninitialized.
Auto Trait Implementations
impl<Tag> RefUnwindSafe for UninitObjectStore<Tag> where
Tag: RefUnwindSafe,
impl<Tag> Unpin for UninitObjectStore<Tag> where
Tag: Unpin,
impl<Tag> UnwindSafe for UninitObjectStore<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