des_sim/context/user.rs
1//! The `user` module defines the `UserContext` trait, which provides a common interface
2//! for models and sources to interact with the simulation environment.
3//!
4//! This trait allows scheduling events and querying the current simulation time.
5
6use crate::modeling::event::EventPriority;
7use crate::modeling::model::Model;
8use crate::primitive::time::{Duration, MicroStep, SimTime};
9
10/// Provides context information accessible by models during simulation execution.
11///
12/// Models use this context to query the current simulation time or to schedule
13/// future events.
14pub trait UserContext<E, M: Model<E>> {
15 /// Returns the current simulation tick (absolute time).
16 fn current_tick(&self) -> SimTime;
17
18 /// Returns the current micro-step (the index of the step within the current tick).
19 fn current_micro_step(&self) -> MicroStep;
20
21 /// Schedules an event with the specified delay and priority.
22 ///
23 /// # Arguments
24 /// * `delay` - The time elapsed from the current simulation time.
25 /// * `priority` - The priority level of the event.
26 /// * `event_payload` - The data payload associated with the scheduled event.
27 fn schedule_event(&mut self, delay: Duration, priority: EventPriority, event_payload: E);
28}