Crate desim [] [src]

This crate implement a discrete event simulation framework inspired by the SimPy library for Python. It uses the generator feature that is nightly. Once the feature is stabilized, also this crate will use stable. Generators will be the only nightly feature used in this crate.


A simulation is performed scheduling one or more processes that models the environment you are going to simulate. Your model may consider some kind of finite resource that must be shared among the processes, e.g. a bunch of servers in a simulation on queues.

After setting up the simulation, it can be run step-by-step, using the step() method, or all at once, with run(), until and ending condition is met.

The simulation will generate a log of all the events.


A process is implemented using the rust generators syntax. This let us avoid the overhead of spawning a new thread for each process, while still keeping the use of this framework quite simple.

When a new process is created in the simulation, an identifier, of type ProcessId is assigned to it. That id can be used to schedule an event that resume the process.

A process can be stopped and resumed later on. To stop the process, the generator yields an Effect that specify what the simulator should do. For example, a generator can set a timeout after witch it is executed again. The process may also return. In that case it can not be resumed anymore.


A resource is a finite amount of entities that can be used by one process a time. When all the instances of the resource of interest are being used by a process, the requiring one is enqueued in a FIFO and is resumed when the resource become available again. When the process does not need the resource anymore, it must release it.

A resource can be created in the simulation using the create_resource method, which requires the amount of resource and returns an identifier for that resource that can be used to require and release it.

A resource can be required and reelased by a process yielding the corresponding Effect. There is no check on the fact that a process yielding Release was holding a resource with that ID, but if a resource gets more release then requests, the simulation will panic.



An event that can be scheduled by a process, yelding the Event Effect or by the owner of a Simulation through the schedule method


This struct provides the methods to create and run the simulation in a single thread.



The effect is yelded by a process generator to interact with the simulation environment.


Specify which condition must be met for the simulation to stop.

Type Definitions


Identifies a process. Can be used to resume it from another one.


Identifies a resource. Can be used to request and release it.