[−][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
None
element, or append to the end) and get anObjId
in return. - Remove object with a specified
ObjId
. - Access object with a specified
ObjId
. - Convert
ObjId
to index and back for specifiedObjPool
.
Features
-
Implements debug-only checks for
ObjId
andObjPool
correspondence. It will panic in debug with some pretty high probability (depending on the actual size of theObjPool
) in case of using anObjId
from the oneObjPool
with anotherObjPool
. It helps a lot to find bugs in case of using manyObjPool
s in the same application with no overhead in release. -
Provides 32-bit long
OptionObjId
type as a memory-footprint optimization replacement forOption<ObjId>
in case you don't need to store more thanu32::max_value() / 2
objects in yourObjPool
.
Limitations:
-
ObjPool
can only store up tou32::max_value() / 2
objects in it in case you are usingOptionObjId
as long asOptionObjId
treatsu32::max_value()
as an universalNone
. -
ObjId
is always 32-bit long.
Examples
Some data structures built using ObjPool<T>
:
Re-exports
pub use optional; |
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 |