Derive Macro bourse_de::agents::Agents

source ·
#[derive(Agents)]
Expand description

Agent iteration macro

Implements the AgentSet trait for a struct with fields of agent types. It’s often the case we want to implement update function that iterates over a heterogeneous set of agents, which this macro automates. For example

#[derive(Agents)]
struct SimAgents {
    a: AgentTypeA,
    b: AgentTypeB,
}

expands to

struct SimAgents {
    a: AgentTypeA,
    b: AgentTypeB,
}

impl AgentSet for SimAgents {
    fn update<R: RngCore>(
        &mut self, env: &mut Env, rng: &mut R
    ) {
        self.a.update(env, rng);
        self.b.update(env, rng);
    }
}