Skip to main content

Source

Trait Source 

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

Source

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.

Source

fn fire( &mut self, context: &mut SourceContext<E, M>, model: &M, ) -> Option<Duration>

Executes the source’s primary logic when triggered.

§Returns

The Duration until the next scheduled fire event, or None if no further events should be scheduled.

Implementors§