A no_std compatible Rust library providing traits for blocking on futures, enabling synchronous code to interact with asynchronous operations.
This crate defines a hierarchy of traits that allow synchronous code to await futures:
Awaiter/AwaiterMut- Safe traits for blocking on futures with shared (&self) or mutable (&mut self) accessUnsafeAwaiter/UnsafeAwaiterMut- Unsafe variants for scenarios requiring manual safety guaranteesCoroutineand related traits - Execute synchronous closures with access to an awaiter within an async context
The crate also provides:
- Dynamic trait objects (
DynAwaiter,DynAwaiterMut, etc.) for type-erased awaiting - An
autoimpl!macro to automatically implement related traits - Optional
embedded-iointegration for bridging async and sync I/O traits
Add to your Cargo.toml:
[dependencies]
awaiter-trait = "0.2"use awaiter_trait::{Awaiter, AwaiterMut};
use core::pin::Pin;
use core::future::Future;
// Implement an awaiter that can block on futures
struct MyAwaiter;
impl Awaiter for MyAwaiter {
fn r#await<T>(&self, f: Pin<&mut (dyn Future<Output = T> + '_)>) -> T {
// Implementation that blocks until the future completes
// ...
}
}
// Use autoimpl! to automatically implement related traits
awaiter_trait::autoimpl!(<> MyAwaiter as Awaiter);The Coroutine traits allow executing synchronous code within an async context:
use awaiter_trait::Coroutine;
async fn example<C: Coroutine>(coro: &C) {
coro.exec(|awaiter| {
// Synchronous code that can use the awaiter
// to block on futures
}).await;
}embedded-io- Enables integration withembedded-ioandembedded-io-asynccrates, providing wrappers to use async I/O types with synchronous interfaces.
- corosensei-awaiter-trait - Provides an implementation of the
Coroutinetrait using thecorosenseicoroutine library, enabling stackful coroutines.
This project is licensed under CC0-1.0.
- Simplify async/sync bridging for embedded and coroutine contexts
- Maintain
no_stdcompatibility
- Core
Awaitertraits defined -
autoimpl!macro available -
embedded-iointegration supported
AI assisted