Expand description
A simple object pool.
ObjPool<T> is basically just a Vec<Option<T>>, which allows you to:
- Insert an object (reuse an existing
Noneelement, or append to the end) and get anObjIdin return. - Remove object with a specified
ObjId. - Access object with a specified
ObjId. - Convert
ObjIdto index and back for specifiedObjPool.
§Limitations:
ObjIdis always 32-bit long.
§Debug-only misuse detection
In debug builds every pool mixes a random pool-specific offset into the ObjIds it issues.
An ObjId used with a different pool than the one that created it then decodes to a vacant
or out-of-bounds slot with overwhelming probability, so the lookup returns None (or panics
when indexing) instead of silently returning an unrelated object. Release builds skip the
masking entirely: an ObjId is just the slot index plus one.
§Examples
Some data structures built using ObjPool<T>:
Structs§
- Into
Iter - An iterator over the occupied slots in a
ObjPool. - Iter
- An iterator over references to the occupied slots in a
ObjPool. - IterMut
- An iterator over mutable references to the occupied slots in a
Arena. - ObjId
- An id of the object in an
ObjPool. - ObjPool
- An object pool.
- ParObj
Pool - A sharded, thread-safe object pool.