pub trait AgentStore<A: Agent> {
// Required methods
fn get(&self, id: AgentId) -> Option<Ref<'_, A>>;
fn get_mut(&self, id: AgentId) -> Option<RefMut<'_, A>>;
fn insert(&mut self, agent: A);
fn remove(&mut self, id: AgentId) -> Option<A>;
fn iter_ids(&self) -> Vec<AgentId> ⓘ;
fn len(&self) -> usize;
// Provided methods
fn contains(&self, id: AgentId) -> bool { ... }
fn iter_ids_into(&self, buf: &mut Vec<AgentId>) { ... }
fn is_empty(&self) -> bool { ... }
}Expand description
Trait for agent containers.
Provides CRUD operations and ID iteration. All access methods take &self
(not &mut self) for reads, using RefCell internally to support
concurrent borrows of different agents.
Required Methods§
Sourcefn insert(&mut self, agent: A)
fn insert(&mut self, agent: A)
Insert an agent into the store.
If an agent with the same ID already exists, it is silently replaced.
Sourcefn remove(&mut self, id: AgentId) -> Option<A>
fn remove(&mut self, id: AgentId) -> Option<A>
Remove and return an agent by ID, or None if not found.
Provided Methods§
Sourcefn iter_ids_into(&self, buf: &mut Vec<AgentId>)
fn iter_ids_into(&self, buf: &mut Vec<AgentId>)
Append all agent IDs into buf without clearing it first.
This avoids allocation when buf is reused across calls.