Skip to main content

Hook

Trait Hook 

Source
pub trait Hook<E, M: Model<E>> {
Show 21 methods // Required methods fn before_simulation(&self, model: &M); fn after_simulation(&self, model: &M, end_tick: SimTime); fn before_tick( &self, model: &M, current_tick: SimTime, skipped_duration: Duration, ); fn after_tick( &self, model: &M, current_tick: SimTime, last_micro_step: MicroStep, ); fn before_micro_step( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, ); fn after_micro_step( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, ); fn on_discard_remain_micro_step( &self, model: &M, current_tick: SimTime, first_discarded_micro_step: MicroStep, discarded_sources: &[SourceReadyEntry], discarded_events: &[Event<E>], ); fn before_register_source(&self, model: &M, name: &str); fn after_register_source(&self, model: &M, name: &str); fn before_source_phase( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, ); fn before_source( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, source_view: &SourceView, ); fn after_source( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, source_view: &SourceView, computed_next_fire: Option<SimTime>, ); fn cancel_source( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, scheduled_at: SimTime, source_view: &SourceView, ); fn discard_source( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, source_view: &SourceView, ); fn after_source_phase( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, ); fn before_event_phase( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, ); fn before_event( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, event: &Event<E>, ); fn after_event( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, event: &Event<E>, ); fn cancel_event( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, scheduled_at: SimTime, event: &Event<E>, ); fn discard_event( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, event: &Event<E>, ); fn after_event_phase( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, );
}
Expand description

A trait for hooking into lifecycle events of a simulation for extension or monitoring.

Implementing Hook allows for logging, tracing, state assertions, or dynamic intervention during simulation execution. Since every method receives the precise simulation state (time, step, model context), this trait provides the foundation for building powerful diagnostic and analysis tools.

Required Methods§

Source

fn before_simulation(&self, model: &M)

Invoked immediately before the simulation starts.

Source

fn after_simulation(&self, model: &M, end_tick: SimTime)

Invoked immediately after the simulation finishes.

Source

fn before_tick( &self, model: &M, current_tick: SimTime, skipped_duration: Duration, )

Invoked at the beginning of a tick process.

§Arguments
  • skipped_duration - The time skipped since the previous tick. When use not-skippable Runner, always 0 duration.
Source

fn after_tick( &self, model: &M, current_tick: SimTime, last_micro_step: MicroStep, )

Invoked immediately after a tick process has completed.

Source

fn before_micro_step( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, )

Invoked at the beginning of a micro-step.

Source

fn after_micro_step( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, )

Invoked at the end of a micro-step.

Source

fn on_discard_remain_micro_step( &self, model: &M, current_tick: SimTime, first_discarded_micro_step: MicroStep, discarded_sources: &[SourceReadyEntry], discarded_events: &[Event<E>], )

Invoked when remaining tasks (events or sources) are discarded due to execution limits.

Source

fn before_register_source(&self, model: &M, name: &str)

Invoked when a source registration begins.

Source

fn after_register_source(&self, model: &M, name: &str)

Invoked when a source registration completes.

Source

fn before_source_phase( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, )

Invoked at the beginning of the source processing phase.

Source

fn before_source( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, source_view: &SourceView, )

Invoked immediately before an individual source fires.

Source

fn after_source( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, source_view: &SourceView, computed_next_fire: Option<SimTime>, )

Invoked immediately after an individual source fires.

Source

fn cancel_source( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, scheduled_at: SimTime, source_view: &SourceView, )

Invoked when a scheduled source is canceled.

Source

fn discard_source( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, source_view: &SourceView, )

Invoked when a source is explicitly discarded.

Source

fn after_source_phase( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, )

Invoked at the end of the source processing phase.

Source

fn before_event_phase( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, )

Invoked at the beginning of the event processing phase.

Source

fn before_event( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, event: &Event<E>, )

Invoked immediately before an event is processed.

Source

fn after_event( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, event: &Event<E>, )

Invoked immediately after an event is processed.

Source

fn cancel_event( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, scheduled_at: SimTime, event: &Event<E>, )

Invoked when a scheduled event is canceled.

Source

fn discard_event( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, event: &Event<E>, )

Invoked when an event is discarded.

Source

fn after_event_phase( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, )

Invoked at the end of the event processing phase.

Implementors§

Source§

impl<E, M> Hook<E, M> for TraceHook
where E: Debug, M: Model<E> + ModelSummary + Debug,

Source§

impl<E, M: Model<E>> Hook<E, M> for InteractiveStepHook

Source§

impl<E, M: Model<E>, H> Hook<E, M> for SharedHook<E, M, H>
where H: Hook<E, M>,