| Crates.io | agnostic-lite |
| lib.rs | agnostic-lite |
| version | 0.6.0 |
| created_at | 2024-03-13 08:34:22.838674+00 |
| updated_at | 2025-11-04 03:05:02.584114+00 |
| description | `agnostic-lite` is an agnostic abstraction layer for any async runtime. |
| homepage | https://github.com/al8n/agnostic |
| repository | https://github.com/al8n/agnostic |
| max_upload_size | |
| id | 1171524 |
| size | 184,088 |
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, this crate is not only no_std, but also alloc-free. This means that it can be used in environments where alloc is not available, such as embedded systems. It also has no unsafe code.
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.
no_std Compatible: Works without the standard library#![forbid(unsafe_code)] ensures memory safetyagnostic-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 operationsRuntimeLite: Combines all traits for convenienceYielder: Yield control back to the runtimefeatures = ["tokio"]features = ["smol"]features = ["wasm"]Choose agnostic-lite over agnostic when:
no_std support for embedded systemsChoose agnostic when:
std[dependencies]
agnostic-lite = "0.6"
Choose one runtime feature:
# With tokio
agnostic-lite = { version = "0.6", features = ["tokio"] }
# With smol
agnostic-lite = { version = "0.6", features = ["smol"] }
# With WASM
agnostic-lite = { version = "0.6", features = ["wasm"] }
# Disable default features for no_std
agnostic-lite = { version = "0.6", default-features = false, features = ["tokio"] }
std (default): Standard library supportalloc: Allocation support (without std)time: Time-related traits and typestokio: Tokio runtime implementationsasync-io: async-io backend (used by smol)smol: Smol runtime implementationswasm: WebAssembly support via wasm-bindgen-futurespub trait AsyncSpawner {
type JoinHandle<T>: Future<Output = Result<T, JoinError>>;
fn spawn<F, T>(future: F) -> Self::JoinHandle<T>
where
F: Future<Output = T> + Send + 'static,
T: Send + 'static;
}
pub trait AsyncLocalSpawner {
type JoinHandle<T>: Future<Output = Result<T, JoinError>>;
fn spawn_local<F, T>(future: F) -> Self::JoinHandle<T>
where
F: Future<Output = T> + 'static,
T: 'static;
}
pub trait AsyncSleep {
type Sleep: Future<Output = ()>;
fn sleep(duration: Duration) -> Self::Sleep;
}
pub trait AsyncInterval {
type Interval: Stream<Item = Instant>;
fn interval(period: Duration) -> Self::Interval;
}
pub trait AsyncTimeout {
fn timeout<F, T>(duration: Duration, future: F) -> TimeoutFuture<F>
where
F: Future<Output = T>;
}
Combines all traits for convenience:
pub trait RuntimeLite:
AsyncSpawner +
AsyncLocalSpawner +
AsyncSleep +
AsyncInterval +
AsyncTimeout +
Yielder
{
// All trait methods available
}
agnostic-lite provides macros for conditional compilation:
use agnostic_lite::{cfg_tokio, cfg_smol};
cfg_tokio! {
// This code only compiles when tokio feature is enabled
use tokio::task;
}
cfg_smol! {
// This code only compiles when smol feature is enabled
use smol::Task;
}
agnostic-lite has zero runtime overhead. All trait methods are inlined and compile to the same code as using the runtime directly:
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.