Crate sittard

Crate sittard 

Source
Expand description

Sittard - A Sans-IO tickless async runtime, fully deterministic.

That’s a mouthful, so let’s unpack it:

  • Async runtime: sittard runs async Rust code, i.e. stuff that implements the Future trait.
  • Sans-IO: sittard doesn’t support asynchronous IO (e.g. network requests, filesystem operations, etc).
  • Tickless: sittard allows async code to “sleep”, but instead of waiting for the time to elapse, sittard advances its virtual clock whenever necessary.
  • Fully deterministic: running the same code under sittard always yields the same results, unless the async code itself is a source of non-determinism.

§Example

use sittard::Runtime;
use std::time::Duration;

// Create a runtime and run a future
let rt = Runtime::default();
rt.block_on(async move {
    let now = sittard::time::Instant::now();
    sittard::time::sleep(Duration::from_secs(60)).await;
    let elapsed_secs = now.elapsed().as_secs_f64();
    println!("Here we are, {elapsed_secs} seconds later...");
});

The code above completes instantly, even though it “sleeps” for 60 seconds.

§Use Cases

Sittard is particularly useful for:

  • Creating reproducible simulations that depend on timing, e.g. QUIC network traffic with deep-space delays
  • Testing time-dependent code without waiting for real time to pass

Note that sittard is unsuitable for common async scenarios like web servers and clients.

Modules§

time
Time-related primitives that work with sittard’s virtual clock

Structs§

AdvanceToNextWake
An implementation of AdvanceClock that advances time to exactly the next timer deadline.
AdvanceToNextWakeWithGranularity
An implementation of AdvanceClock that advances time according to a user-specified clock granularity.
JoinHandle
A handle to a spawned task that can be awaited to get the task’s result.
Runtime
The main async runtime for sittard.
SendRuntime
A wrapper around Runtime that implements Send.

Traits§

AdvanceClock
Controls how sittard’s virtual clock advances

Functions§

spawn
Spawns a new task on the currently active runtime.

Attribute Macros§

test