docs.rs failed to build switchy_async-0.3.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
switchy_async-0.2.0
MoosicBox Async
Async runtime abstraction and utilities for MoosicBox applications.
Overview
The MoosicBox Async package provides:
- Runtime Abstraction: Generic async runtime interface
- Multi-Backend: Support for Tokio and simulation runtimes
- Builder Pattern: Flexible runtime configuration
- Feature-Gated: Modular async functionality
- Thread Management: Thread ID tracking and management
Features
Runtime Abstraction
- GenericRuntime: Common interface for all async runtimes
- Runtime Builder: Configurable runtime construction
- Backend Selection: Choose between Tokio and simulation runtimes
- Future Support: Standard Future trait integration
Backend Support
- Tokio: Production async runtime
- Simulator: Deterministic simulation runtime for testing
- Feature-Gated: Enable only needed backends
Async Utilities
- Thread ID: Unique thread identification
- Task Management: Task spawning and joining
- IO Operations: Async I/O primitives (feature-gated)
- Synchronization: Async synchronization primitives (feature-gated)
- Timers: Async timing utilities (feature-gated)
Installation
Add this to your Cargo.toml:
[]
= "0.1.4"
With Tokio backend features:
[]
= { = "0.1.4", = false, = ["tokio", "rt-multi-thread", "io", "sync", "time", "macros"] }
For testing with simulation:
[]
= { = "0.1.4", = false, = ["simulator", "macros"] }
Usage
Runtime Creation
use ;
// Create runtime with default settings (current-thread)
let runtime = new.build?;
// Use generic runtime interface
runtime.block_on;
// Wait for runtime to complete
runtime.wait?;
// With multi-threaded runtime (requires rt-multi-thread feature)
Backend-Specific Usage
// Tokio backend (when tokio feature enabled)
use ;
// Additional modules available with features
use io; // Async I/O traits and utilities
use sync; // Synchronization primitives
use util; // Additional utilities
Simulation Backend
// Simulation backend (when simulator feature enabled)
use simulator;
Thread Management
use thread_id;
// Get unique thread ID
let id = thread_id;
println!;
Macros and Utilities
// Async macros (requires macros feature)
use ;
// Yield injection for simulation testing (requires macros feature)
use ;
async
// Runtime entry-point macros
async
async
Error Handling
use Error;
// Runtime errors
match runtime.wait
// Task join errors (when using task handles)
use JoinError;
let handle = runtime.spawn;
match handle.await
Feature Flags
Backend Selection
tokio: Enable Tokio async runtimesimulator: Enable simulation runtime for testing
Runtime Features
rt-multi-thread: Multi-threaded runtime supportfs: File system operationsio: Async I/O operationsnet: Networking supportprocess: Process managementsync: Synchronization primitives (includes channels)time: Timing utilitiesutil: Additional utilitiesmacros: Async macros (select!, join!, try_join!, etc.)
Macro Features
macros: Enable async macros and yield injection utilities
Runtime Comparison
Tokio Runtime
- Production: Optimized for production use
- Performance: High-performance async execution
- Ecosystem: Full Tokio ecosystem support
- Threading: Multi-threaded execution
Simulation Runtime
- Testing: Deterministic execution for tests
- Reproducible: Consistent behavior across runs
- Debugging: Easier debugging and tracing
- Controlled: Precise control over execution order
Dependencies
Core dependencies:
- thiserror: Error handling
- pin-project-lite: Pin projection utilities
- scoped-tls: Scoped thread-local storage
- log: Logging facade
Feature-gated dependencies:
- futures: Core Future trait and utilities (enabled with backend features)
- tokio: Tokio async runtime (optional, enabled with
tokiofeature) - tokio-util: Additional Tokio utilities (optional, enabled with
tokioorutilfeatures) - flume: MPSC/MPMC channel implementation (optional, enabled with
syncfeature) - switchy_async_macros: Macro utilities (optional, enabled with
macrosfeature) - switchy_random: Random number generation for simulator (optional, enabled with
simulatorfeature) - switchy_time: Time utilities for simulator (optional, enabled with
simulatorfeature)
Integration
This package is designed for:
- Application Runtime: Main async runtime for applications
- Testing: Deterministic async testing with simulation
- Library Development: Runtime-agnostic async libraries
- Performance: High-performance async applications
- Cross-Platform: Consistent async behavior across platforms