Skip to main content

TrafficSource

Trait TrafficSource 

Source
pub trait TrafficSource {
    // Required method
    fn generate(&mut self, tick: u64) -> Vec<SpawnRequest>;
}
Expand description

Trait for external traffic generators.

Implementors produce zero or more SpawnRequests per tick. The consumer is responsible for feeding them into the simulation:

for req in source.generate(tick) {
    sim.spawn_rider(req.origin, req.destination, req.weight)?;
}

This design keeps traffic generation external to the simulation loop, giving consumers full control over when and how riders are spawned.

Required Methods§

Source

fn generate(&mut self, tick: u64) -> Vec<SpawnRequest>

Generate spawn requests for the given tick.

May return an empty vec (no arrivals this tick) or multiple requests (burst arrivals). The implementation controls the arrival process.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§