Skip to main content

Model

Trait Model 

Source
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§

Source

type Agent: Agent

The agent type stored in this model.

Source

type Space: Space

The space type used by this model.

Source

type Properties

User-defined model properties (can be () if unused).

Source

type Rng: RngCore

The random number generator type.

Source

type AgentRef<'a>: Deref<Target = Self::Agent> where Self: 'a

Borrowed reference to an agent (may be Ref<'a, A> for RefCell-based stores).

Source

type AgentRefMut<'a>: DerefMut<Target = Self::Agent> where Self: 'a

Mutably borrowed reference to an agent (may be RefMut<'a, A>).

Required Methods§

Source

fn time(&self) -> Time

Current simulation time.

Source

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.

Source

fn space(&self) -> &Self::Space

Immutable reference to the simulation space.

Source

fn properties(&self) -> &Self::Properties

Immutable reference to user-defined properties.

Source

fn properties_mut(&mut self) -> &mut Self::Properties

Mutable reference to user-defined properties.

Source

fn agent(&self, id: AgentId) -> Option<Self::AgentRef<'_>>

Look up an agent by ID, returning a borrowed reference.

Source

fn agent_mut(&self, id: AgentId) -> Option<Self::AgentRefMut<'_>>

Look up an agent by ID, returning a mutably borrowed reference.

Provided Methods§

Source

fn has_id(&self, id: AgentId) -> bool

Check whether an agent with the given ID exists.

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.

Implementors§

Source§

impl<S, A, Store, Props, R> Model for EventQueueModel<S, A, Store, Props, R>
where A: Agent, S: Space, Store: AgentStore<A>, R: RngCore,

Source§

type Agent = A

Source§

type Space = S

Source§

type Properties = Props

Source§

type Rng = R

Source§

type AgentRef<'a> = Ref<'a, A> where Self: 'a

Source§

type AgentRefMut<'a> = RefMut<'a, A> where Self: 'a

Source§

impl<S, A, Store, Props, R, Sch> Model for StandardModel<S, A, Store, Props, R, Sch>
where A: Agent, S: Space, Store: AgentStore<A>, R: RngCore,

Source§

type Agent = A

Source§

type Space = S

Source§

type Properties = Props

Source§

type Rng = R

Source§

type AgentRef<'a> = Ref<'a, A> where Self: 'a

Source§

type AgentRefMut<'a> = RefMut<'a, A> where Self: 'a