agnostic-lite is an agnostic abstraction layer for any async runtime.
In order to make it trivial for others to build implementations of any async runtime, this crate provides an abstraction layer implementation.
In addition, the abstraction layer itself is no_std and alloc-free, so the traits can be used in environments where alloc is not available. It also has no unsafe code. Concrete runtime backends have their own requirements: tokio, smol, and wasm require std, while the embassy backend is no_std but requires alloc.
Introduction
agnostic-lite is a lightweight, no_std-compatible, allocation-free abstraction layer for async runtimes. It provides the essential async primitives you need to write runtime-agnostic code that works in any environment - from standard applications to embedded systems.
Key Features
no_stdCompatible: Works without the standard library- Allocation-Free: No heap allocations required
- No Unsafe Code:
#![forbid(unsafe_code)]ensures memory safety - Modular Traits: Small, focused traits instead of one monolithic Runtime trait
- Zero-Cost: Compiles to runtime-specific code
- WASM Support: Works in WebAssembly environments
Core Traits
agnostic-lite provides focused traits for specific async operations:
AsyncSpawner: Spawn tasks globallyAsyncLocalSpawner: Spawn thread-local tasksAsyncSleep: Sleep for a durationAsyncInterval: Create periodic intervalsAsyncTimeout: Apply timeouts to operationsLocalRuntimeLite: The thread-pinned runtime core — construction,block_on, local/blocking spawning, and the!Send-tolerant time familyRuntimeLite: TheSendextension ofLocalRuntimeLite— multithread spawning and theSendtime family (bounds on it reach every core item too)Yielder: Yield control back to the runtime
Supported Runtimes
- tokio - Enable with
features = ["tokio"](requiresstd) - smol - Enable with
features = ["smol"](requiresstd) - wasm-bindgen-futures - Enable with
features = ["wasm"](requiresstd) - embassy - Enable with
features = ["embassy"]; theno_stdruntime for embedded targets (requiresalloc)
Why agnostic-lite?
Choose agnostic-lite over agnostic when:
- ✅ You need
no_stdsupport for embedded systems - ✅ You want minimal dependencies and compile times
- ✅ You only need basic async primitives (spawning, time)
- ✅ You're building a library and want minimal footprint
- ✅ You need guaranteed memory safety (no unsafe code)
Choose agnostic when:
- You need networking, DNS, or process management
- You're building standard applications with
std - You want a batteries-included experience
Installation
[]
= "0.7"
Runtime Selection
Choose one runtime feature:
# With tokio
= { = "0.7", = ["tokio"] }
# With smol
= { = "0.7", = ["smol"] }
# With WASM
= { = "0.7", = ["wasm"] }
no_std Usage
The tokio, smol, and wasm runtimes all pull in std. For a real no_std runtime, use the
embassy backend, which targets embassy-executor and only requires alloc:
# no_std (with alloc), for embedded targets running on embassy-executor
= { = "0.7", = false, = ["embassy"] }
The embassy backend has caveats (a one-time spawner init, a bounded task pool, a busy-polling
block_on, and panicking spawn_blocking/local spawning) — see the embassy module docs.
Feature Flags
Core Features
std(default): Standard library supportalloc: Allocation support (without std)time: Time-related traits and types
Runtime Features (choose one)
tokio: Tokio runtime implementations (requiresstd)async-io: async-io backend (used by smol, requiresstd)smol: Smol runtime implementations (requiresstd)wasm: WebAssembly support via wasm-bindgen-futures (requiresstd)embassy:no_stdruntime for embedded targets via embassy-executor (requiresalloc)
Trait Reference
The signatures below are simplified sketches for orientation; see docs.rs for the authoritative definitions.
AsyncSpawner
AsyncLocalSpawner
AsyncSleep
AsyncInterval
AsyncTimeout
LocalRuntimeLite and RuntimeLite
Since 0.7 the runtime abstraction is two traits. LocalRuntimeLite is the
thread-pinned core — everything a consumer needs to host futures on the
current thread — and RuntimeLite is its Send extension. A thread-pinned
host (a LocalSet-shaped executor, or any runtime whose timers are
deliberately !Send) can implement the core alone; tokio/smol/wasm/embassy
implement both. Completion-based (proactor) runtimes such as compio are
deliberately out of scope: their I/O model warrants a native driver
integration of its own, not this reactor-shaped abstraction wrapped around
it. This is a trimmed sketch:
Generic R: RuntimeLite bounds reach every core item through the supertrait
unchanged. Concrete-type calls of moved members (SmolRuntime::block_on(..))
need LocalRuntimeLite in scope, and UFCS calls must name the owning trait.
Conditional Compilation Helpers
agnostic-lite provides macros for conditional compilation:
use ;
cfg_tokio!
cfg_smol!
Performance
agnostic-lite has zero runtime overhead. All trait methods are inlined and compile to the same code as using the runtime directly:
- No allocations: Works without heap allocations
- No dynamic dispatch: All trait calls are statically resolved
- Zero-cost abstractions: Compiles to identical assembly as direct runtime usage
License
agnostic-lite is under the terms of both the MIT license and the
Apache License (Version 2.0).
See LICENSE-APACHE, LICENSE-MIT for details.
Copyright (c) 2025 Al Liu.