Struct 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§

Source§

impl UninitObjectStore<ThreadLocal>

Source

pub fn new_thread_local() -> Self

Instantiates a new UninitObjectStore object that can store objects which are !Send and !Sync.

Source§

impl UninitObjectStore<Send>

Source

pub fn new_send() -> Self

Instantiates a new UninitObjectStore object that can store objects which are Send but !Sync.

Source§

impl UninitObjectStore<SendSync>

Source

pub fn new_sync() -> Self

Instantiates a new UninitObjectStore object that can store objects which are Send and Sync.

Source§

impl<Tag> UninitObjectStore<Tag>

Source

pub fn new() -> Self

Instantiates a new UninitObjectStore object.

Source

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).

Source

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.

Source

pub fn count_unwritten_handles(&self) -> usize

Returns the number of objects in this store that are yet to be written.

Source

pub fn can_init(&self) -> bool

Returns true if a call to UninitObjectStore::try_init will succeed.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

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.

Source§

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> Freeze for UninitObjectStore<Tag>

§

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§

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.
Source§

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

Source§

impl<T> Satisfies<SendSync> for T
where T: Send + Sync,

Source§

impl<T> Satisfies<ThreadLocal> for T