[−][src]Crate obj_pool
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.
Features
-
Implements debug-only checks for
ObjIdandObjPoolcorrespondence. It will panic in debug with some pretty high probability (depending on the actual size of theObjPool) in case of using anObjIdfrom the oneObjPoolwith anotherObjPool. It helps a lot to find bugs in case of using manyObjPools in the same application with no overhead in release. -
Provides 32-bit long
OptionObjIdtype as a memory-footprint optimization replacement forOption<ObjId>in case you don't need to store more thanu32::max_value() / 2objects in yourObjPool.
Limitations:
-
ObjPoolcan only store up tou32::max_value() / 2objects in it in case you are usingOptionObjIdas long asOptionObjIdtreatsu32::max_value()as an universalNone. -
ObjIdis always 32-bit long.
Examples
Some data structures built using ObjPool<T>:
Structs
| IntoIter | An iterator over the occupied slots in a |
| Iter | An iterator over references to the occupied slots in a |
| IterMut | An iterator over mutable references to the occupied slots in a |
| ObjId | An id of the object in an |
| ObjPool | An object pool. |
Type Definitions
| OptionObjId | Optimization for |