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§
Sourcefn before_simulation(&self, model: &M)
fn before_simulation(&self, model: &M)
Invoked immediately before the simulation starts.
Sourcefn after_simulation(&self, model: &M, end_tick: SimTime)
fn after_simulation(&self, model: &M, end_tick: SimTime)
Invoked immediately after the simulation finishes.
Sourcefn before_tick(
&self,
model: &M,
current_tick: SimTime,
skipped_duration: Duration,
)
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-skippableRunner, always 0 duration.
Sourcefn after_tick(
&self,
model: &M,
current_tick: SimTime,
last_micro_step: MicroStep,
)
fn after_tick( &self, model: &M, current_tick: SimTime, last_micro_step: MicroStep, )
Invoked immediately after a tick process has completed.
Sourcefn before_micro_step(
&self,
model: &M,
current_tick: SimTime,
current_micro_step: MicroStep,
)
fn before_micro_step( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, )
Invoked at the beginning of a micro-step.
Sourcefn after_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, )
Invoked at the end of a micro-step.
Sourcefn on_discard_remain_micro_step(
&self,
model: &M,
current_tick: SimTime,
first_discarded_micro_step: MicroStep,
discarded_sources: &[SourceReadyEntry],
discarded_events: &[Event<E>],
)
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.
Sourcefn before_register_source(&self, model: &M, name: &str)
fn before_register_source(&self, model: &M, name: &str)
Invoked when a source registration begins.
Sourcefn after_register_source(&self, model: &M, name: &str)
fn after_register_source(&self, model: &M, name: &str)
Invoked when a source registration completes.
Sourcefn before_source_phase(
&self,
model: &M,
current_tick: SimTime,
current_micro_step: MicroStep,
)
fn before_source_phase( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, )
Invoked at the beginning of the source processing phase.
Sourcefn before_source(
&self,
model: &M,
current_tick: SimTime,
current_micro_step: MicroStep,
source_view: &SourceView,
)
fn before_source( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, source_view: &SourceView, )
Invoked immediately before an individual source fires.
Sourcefn after_source(
&self,
model: &M,
current_tick: SimTime,
current_micro_step: MicroStep,
source_view: &SourceView,
computed_next_fire: Option<SimTime>,
)
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.
Sourcefn cancel_source(
&self,
model: &M,
current_tick: SimTime,
current_micro_step: MicroStep,
scheduled_at: SimTime,
source_view: &SourceView,
)
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.
Sourcefn discard_source(
&self,
model: &M,
current_tick: SimTime,
current_micro_step: MicroStep,
source_view: &SourceView,
)
fn discard_source( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, source_view: &SourceView, )
Invoked when a source is explicitly discarded.
Sourcefn after_source_phase(
&self,
model: &M,
current_tick: SimTime,
current_micro_step: MicroStep,
)
fn after_source_phase( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, )
Invoked at the end of the source processing phase.
Sourcefn before_event_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, )
Invoked at the beginning of the event processing phase.
Sourcefn before_event(
&self,
model: &M,
current_tick: SimTime,
current_micro_step: MicroStep,
event: &Event<E>,
)
fn before_event( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, event: &Event<E>, )
Invoked immediately before an event is processed.
Sourcefn after_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>, )
Invoked immediately after an event is processed.
Sourcefn cancel_event(
&self,
model: &M,
current_tick: SimTime,
current_micro_step: MicroStep,
scheduled_at: SimTime,
event: &Event<E>,
)
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.
Sourcefn discard_event(
&self,
model: &M,
current_tick: SimTime,
current_micro_step: MicroStep,
event: &Event<E>,
)
fn discard_event( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, event: &Event<E>, )
Invoked when an event is discarded.
Sourcefn after_event_phase(
&self,
model: &M,
current_tick: SimTime,
current_micro_step: MicroStep,
)
fn after_event_phase( &self, model: &M, current_tick: SimTime, current_micro_step: MicroStep, )
Invoked at the end of the event processing phase.