pub struct ParObjPool<T, const S: usize> { /* private fields */ }Expand description
A sharded, thread-safe object pool.
An external ObjId packs the shard index into its highest SHARD_BITS
bits, where SHARD_BITS is the smallest number of bits able to represent
all shard indices 0..S. The remaining low bits hold the object index
inside the shard, so each shard can hold up to 2^(32 - SHARD_BITS) - 1
objects.
In debug builds every ParObjPool additionally mixes its own random tag
into the external ObjIds it issues, so ids of one pool are (with
overwhelming probability) rejected by any other pool. See the crate-level
documentation for details.
Implementations§
Source§impl<T, const S: usize> ParObjPool<T, S>
impl<T, const S: usize> ParObjPool<T, S>
pub fn new() -> Self
pub fn insert(&self, object: T) -> ObjId
pub fn remove(&self, obj_id: ObjId) -> Option<T>
pub fn get(&self, obj_id: ObjId) -> Option<MappedRwLockReadGuard<'_, T>>
pub fn try_get(&self, obj_id: ObjId) -> Option<MappedRwLockReadGuard<'_, T>>
pub fn get_mut(&self, obj_id: ObjId) -> Option<MappedRwLockWriteGuard<'_, T>>
pub fn try_get_mut( &self, obj_id: ObjId, ) -> Option<MappedRwLockWriteGuard<'_, T>>
pub fn clear(&self)
pub fn shrink_to_fit(&self)
pub fn capacity(&self) -> usize
Trait Implementations§
Auto Trait Implementations§
impl<T, const S: usize> !Freeze for ParObjPool<T, S>
impl<T, const S: usize> !RefUnwindSafe for ParObjPool<T, S>
impl<T, const S: usize> Send for ParObjPool<T, S>where
T: Send,
impl<T, const S: usize> Sync for ParObjPool<T, S>
impl<T, const S: usize> Unpin for ParObjPool<T, S>where
T: Unpin,
impl<T, const S: usize> UnsafeUnpin for ParObjPool<T, S>
impl<T, const S: usize> UnwindSafe for ParObjPool<T, S>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more