pub trait SimState {
// Required methods
fn call_agents<D: DB, V: Validator, R: RngCore>(
&mut self,
rng: &mut R,
env: &mut Env<D, V>,
) -> Vec<Transaction>;
fn record_agents<D: DB, V: Validator>(&mut self, env: &mut Env<D, V>);
}Expand description
Simulation agent state trait
Trait providing an interface to update the state of all agents over the course of a simulation. This trait can be automatically derived for a struct where the fields are sets of agents of a single type using the SimState macro. This will generate the code to automatically iterate over each set of agents in turn.
§Examples
use rand::RngCore;
use alloy_primitives::Address;
use verbs_rs::{DB, env::{Env, Validator}};
use verbs_rs::agent::{Agent, RecordedAgent, AgentVec, AgentSet, SimState};
use verbs_rs::contract::Transaction;
struct DummyAgent{}
impl Agent for DummyAgent {
fn update<D: DB, V: Validator, R: RngCore>(
&mut self, rng: &mut R, network: &mut Env<D, V>
) -> Vec<Transaction> {
Vec::default()
}
fn get_address(&self) -> Address {
Address::ZERO
}
}
impl RecordedAgent<bool> for DummyAgent {
fn record<D: DB, V: Validator>(&mut self, _env: &mut Env<D, V>) -> bool {
true
}
}
#[derive(SimState)]
struct TestState {
a: AgentVec::<bool, DummyAgent>,
b: AgentVec::<bool, DummyAgent>,
}Required Methods§
Sourcefn call_agents<D: DB, V: Validator, R: RngCore>(
&mut self,
rng: &mut R,
env: &mut Env<D, V>,
) -> Vec<Transaction>
fn call_agents<D: DB, V: Validator, R: RngCore>( &mut self, rng: &mut R, env: &mut Env<D, V>, ) -> Vec<Transaction>
Update the state of all agents, and return any transactions
Sourcefn record_agents<D: DB, V: Validator>(&mut self, env: &mut Env<D, V>)
fn record_agents<D: DB, V: Validator>(&mut self, env: &mut Env<D, V>)
Record the current state of the agents in this set
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.