Expand description
§Item Pool
A lightweight library for managing pools of reusable items with support for random selection, unique set retrieval, and item recycling.
§Features
- Random Item Selection: Efficiently retrieve random items from a pool
- Unique Sets: Get sets of unique items without duplicates
- Item Recycling: Temporarily discard items and recycle them back into the pool
- Zero Dependencies: Only uses
randfor randomization
§Example
use itempool::{ItemPool, RecyclingItemPool};
use std::collections::HashSet;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
struct EntityId(u32);
struct EnemyPool {
available: Vec<EntityId>,
discarded: Vec<EntityId>,
}
impl ItemPool<EntityId> for EnemyPool {
fn pool(&mut self) -> &mut Vec<EntityId> {
&mut self.available
}
}
impl RecyclingItemPool<EntityId> for EnemyPool {
fn get_discard_pool(&mut self) -> &mut Vec<EntityId> {
&mut self.discarded
}
}Traits§
- Item
Pool - Trait for a resource that manages a single store of items.
- Pool
Item - Trait for items that can be stored and retrieved from an item pool.
- Recycling
Item Pool - Trait for managing item pools with discard and recycling capabilities.