Skip to main content

Crate switchy

Crate switchy 

Source
Expand description

Core simulation harness APIs.

Re-exports all public types, traits, and functions from simvar_harness, including run_simulation, Sim, SimBootstrap, and SimConfig. Runtime abstraction layer for testing and simulation.

switchy provides runtime-agnostic interfaces for async operations, I/O, networking, and other system interactions. It enables code to be written once and run against different backends (e.g., Tokio, simulator) by switching feature flags.

§Feature Flags

This crate uses feature flags extensively to control which backends are enabled:

  • async - Core async runtime abstractions via switchy_async
  • async-tokio - Use Tokio as the async runtime
  • simulator - Use simulated runtime for deterministic testing
  • async-macros - Enable async macros like select!, join!, try_join!
  • database - Database abstraction layer
  • fs - Filesystem abstraction layer
  • http - HTTP client abstraction layer
  • tcp - TCP networking abstraction layer
  • time - Time and timing abstractions
  • all - Enable all features (default)

§Examples

use switchy::unsync::time::{sleep, Duration};

// This code works with both Tokio and simulator runtimes
sleep(Duration::from_secs(1)).await;

Modules§

database
Database Abstraction Layer for Switchy Ecosystem
database_connection
Database connection initialization and credential management.
fs
Switchy filesystem abstraction layer with support for real and simulated filesystems.
http
HTTP client and model abstractions.
mdns
mDNS service registration and discovery for MoosicBox servers.
random
Thread-safe random number generation with pluggable backends.
tcp
Generic TCP stream and listener abstractions for async Rust.
telemetry
OpenTelemetry-based telemetry and metrics collection for Switchy services.
time
Time utilities with support for both standard system time and simulated time.
unsync
Async runtime abstractions and utilities.
unsync_macros
Internal macro support for async operations.
upnp
UPnP/DLNA device discovery and control library.
web_server
A flexible, backend-agnostic HTTP web server framework for Rust.

Macros§

join
Waits for multiple concurrent futures, returning when all complete.
select
Waits on multiple concurrent branches, returning when the first completes.
try_join
Waits for multiple fallible concurrent futures, returning when all complete successfully.