Skip to main content

Crate descartes_core

Crate descartes_core 

Source
Expand description

Core discrete event simulation engine.

This crate provides the fundamental building blocks for discrete event simulation: time management, event scheduling, task execution, and component-based architecture.

§Architecture Overview

The simulation is built around two main types:

  • Simulation: The main entry point that owns the scheduler and components. Use this to run simulations, add components, and access simulation state.

  • SchedulerHandle: A cloneable handle for scheduling events during simulation. Pass this to Tower service layers and other components that need to schedule events without direct access to the simulation.

§Basic Usage

use descartes_core::{Simulation, SimTime, Executor};
use std::time::Duration;

// Create a simulation
let mut simulation = Simulation::default();

// Get a scheduler handle for Tower layers or other components
let scheduler = simulation.scheduler_handle();

// Schedule events, add components, run simulation
simulation.execute(Executor::unbound());

§Scheduling Events

For simple scheduling from within the simulation:

simulation.schedule(SimTime::from_millis(100), component_key, MyEvent::Tick);

For Tower layers or components that need a cloneable handle:

let scheduler = simulation.scheduler_handle();
scheduler.schedule(SimTime::from_millis(100), component_key, MyEvent::Tick);

§Time Model

All timing uses SimTime, which represents simulation time (not wall-clock time). This ensures deterministic, reproducible behavior across simulation runs.

Re-exports§

pub use error::EventError;
pub use error::SimError;
pub use execute::Execute;
pub use execute::Executor;
pub use logging::component_span;
pub use logging::event_span;
pub use logging::init_detailed_simulation_logging;
pub use logging::init_simulation_logging;
pub use logging::init_simulation_logging_with_level;
pub use logging::simulation_span;
pub use logging::task_span;
pub use randomness::DrawSite;
pub use randomness::RandomProvider;
pub use request::AttemptStatus;
pub use request::Request;
pub use request::RequestAttempt;
pub use request::RequestAttemptId;
pub use request::RequestId;
pub use request::RequestStatus;
pub use request::Response;
pub use request::ResponseStatus;
pub use scheduler::current_time;
pub use scheduler::defer_wake;
pub use scheduler::defer_wake_after;
pub use scheduler::in_scheduler_context;
pub use scheduler::ClockRef;
pub use scheduler::EventEntry;
pub use scheduler::EventFrontierPolicy;
pub use scheduler::FifoFrontierPolicy;
pub use scheduler::FrontierEvent;
pub use scheduler::FrontierEventKind;
pub use scheduler::FrontierSignature;
pub use scheduler::Scheduler;
pub use scheduler::SchedulerHandle;
pub use scheduler::UniformRandomFrontierPolicy;
pub use task::ClosureTask;
pub use task::PeriodicTask;
pub use task::RetryTask;
pub use task::Task;
pub use task::TaskHandle;
pub use task::TaskId;
pub use task::TimeoutTask;
pub use time::SimTime;
pub use types::EventId;
pub use waker::create_des_waker;
pub use formal::CertificateError;
pub use formal::LyapunovError;
pub use formal::VerificationError;

Modules§

async_runtime
DES-based async runtime.
dists
Distribution traits and implementations for arrival patterns and service times
error
Error types for the simulation framework
execute
formal
Formal reasoning capabilities for simulation verification
ids
logging
Structured logging for discrete event simulation debugging
randomness
Randomness facade for deterministic simulation.
request
Request and response data models for distributed system simulation
scheduler
Event scheduling and time management for discrete event simulation.
task
Task system for short-lived operations in DES
time
Simulation time management
types
Core type definitions and newtypes for the simulation framework
waker
Unified DES waker utilities.

Macros§

draw_site
Generate a DrawSite at the macro expansion site.
sim_debug
sim_error
sim_info
sim_log_with_time
Helper for logging with simulation time context
sim_trace
Macros for convenient logging with simulation context
sim_warn

Structs§

Components
Container holding type-erased components.
Key
Simulation
Simulation struct that puts different parts of the simulation together.
SimulationConfig
Global configuration for a simulation.

Traits§

Component
ProcessEventEntry