pub trait Model {
type Agent: Agent;
type Space: Space;
type Properties;
type Rng: RngCore;
type AgentRef<'a>: Deref<Target = Self::Agent>
where Self: 'a;
type AgentRefMut<'a>: DerefMut<Target = Self::Agent>
where Self: 'a;
// Required methods
fn time(&self) -> Time;
fn rng_mut(&self) -> impl DerefMut<Target = Self::Rng> + '_;
fn space(&self) -> &Self::Space;
fn properties(&self) -> &Self::Properties;
fn properties_mut(&mut self) -> &mut Self::Properties;
fn agent(&self, id: AgentId) -> Option<Self::AgentRef<'_>>;
fn agent_mut(&self, id: AgentId) -> Option<Self::AgentRefMut<'_>>;
// Provided method
fn has_id(&self, id: AgentId) -> bool { ... }
}Expand description
The abstract model interface.
Provides read access to the simulation state (time, space, properties, agents) and mutable access to the RNG. Concrete model types add stepping methods.
§Generic Associated Types
AgentRef and AgentRefMut are GATs that allow models using interior
mutability (e.g. RefCell) to return borrowed references without
requiring &mut self for agent access.
Required Associated Types§
Sourcetype Properties
type Properties
User-defined model properties (can be () if unused).
Sourcetype AgentRef<'a>: Deref<Target = Self::Agent>
where
Self: 'a
type AgentRef<'a>: Deref<Target = Self::Agent> where Self: 'a
Borrowed reference to an agent (may be Ref<'a, A> for RefCell-based stores).
Sourcetype AgentRefMut<'a>: DerefMut<Target = Self::Agent>
where
Self: 'a
type AgentRefMut<'a>: DerefMut<Target = Self::Agent> where Self: 'a
Mutably borrowed reference to an agent (may be RefMut<'a, A>).
Required Methods§
Sourcefn rng_mut(&self) -> impl DerefMut<Target = Self::Rng> + '_
fn rng_mut(&self) -> impl DerefMut<Target = Self::Rng> + '_
Mutable access to the model’s RNG.
Takes &self (not &mut self) because the RNG is stored behind interior
mutability, allowing agent step functions to use it without borrowing
the entire model exclusively.
Sourcefn properties(&self) -> &Self::Properties
fn properties(&self) -> &Self::Properties
Immutable reference to user-defined properties.
Sourcefn properties_mut(&mut self) -> &mut Self::Properties
fn properties_mut(&mut self) -> &mut Self::Properties
Mutable reference to user-defined properties.
Sourcefn agent(&self, id: AgentId) -> Option<Self::AgentRef<'_>>
fn agent(&self, id: AgentId) -> Option<Self::AgentRef<'_>>
Look up an agent by ID, returning a borrowed reference.
Sourcefn agent_mut(&self, id: AgentId) -> Option<Self::AgentRefMut<'_>>
fn agent_mut(&self, id: AgentId) -> Option<Self::AgentRefMut<'_>>
Look up an agent by ID, returning a mutably borrowed reference.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.