pub trait Source<E, M: Model<E>>: Send {
// Required methods
fn on_registered(
&mut self,
context: &mut dyn UserContext<E, M>,
model: &M,
) -> Option<Duration>;
fn fire(
&mut self,
context: &mut SourceContext<E, M>,
model: &M,
) -> Option<Duration>;
}Expand description
Defines the interface for a simulation source.
Sources are responsible for scheduling events or influencing the simulation based on their internal logic.
Required Methods§
Sourcefn on_registered(
&mut self,
context: &mut dyn UserContext<E, M>,
model: &M,
) -> Option<Duration>
fn on_registered( &mut self, context: &mut dyn UserContext<E, M>, model: &M, ) -> Option<Duration>
Callback executed when the source is registered.
This is invoked regardless of whether the simulation has started or is currently running.
The context provides access to either SourceContext (at startup) or
EventContext (during runtime).
§Warning
If this method schedules an event with Duration::zero() that re-registers this source, it may result in an infinite micro-step loop.