[][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 an ObjId in return.
  • Remove object with a specified ObjId.
  • Access object with a specified ObjId.
  • Convert ObjId to index and back for specified ObjPool.


  • Implements debug-only checks for ObjId and ObjPool correspondence. It will panic in debug with some pretty high probability (depending on the actual size of the ObjPool) in case of using an ObjId from the one ObjPool with another ObjPool. It helps a lot to find bugs in case of using many ObjPools in the same application with no overhead in release.

  • Provides 32-bit long OptionObjId type as a memory-footprint optimization replacement for Option<ObjId> in case you don't need to store more than u32::max_value() / 2 objects in your ObjPool.


  • ObjPool can only store up to u32::max_value() / 2 objects in it in case you are using OptionObjId as long as OptionObjId treats u32::max_value() as an universal None.

  • ObjId is always 32-bit long.


Some data structures built using ObjPool<T>:


pub use optional;



An iterator over the occupied slots in a ObjPool.


An iterator over references to the occupied slots in a ObjPool.


An iterator over mutable references to the occupied slots in a Arena.


An id of the object in an ObjPool.


An object pool.

Type Definitions


Optimization for Option<ObjId> which treats ObjId of u32::max_value() as None. It's safe to store any ObjPool ObjId in this wrapper as long as the size of the ObjPool is less than u32::max_value() / 2.