application-toys-macros
Procedural macros for the application-toys crate.
Overview
This crate provides two attribute macros:
#[asynchronous]— makesasync fnmethods intraitandimplblocks dyn-compatible by rewriting them to returnPin<Box<dyn Future<Output = T> + Send + Sync + 'lt>>.#[responsible]— appends atokio::sync::oneshot::Sender<T>to marked enum variants, enforcing a request/response ownership pattern at the type level.
Note: You normally do not depend on this crate directly — use
application-toyswith theeventfeature instead, which activates both macros.
Features
| Feature | Default | Description |
|---|---|---|
asynchronous-traits |
Enables #[asynchronous] |
|
event |
Enables #[responsible] |
#[asynchronous]
Apply to a trait or impl block to make every async fn inside it return a boxed, dyn-compatible future.
Trait declaration
use asynchronous;
Expands to:
Impl block
use asynchronous;
;
Trait with a default implementation
use asynchronous;
Optional flags
Pass comma-separated flags inside the attribute:
| Flag | Effect |
|---|---|
no_sync |
Remove the Sync bound; keep only Send |
local |
Remove both Send and Sync (single-threaded runtimes) |
static_lifetime |
Force 'static even when a borrowed receiver is present |
use asynchronous;
Lifetime inference
| Receiver | Future lifetime |
|---|---|
&self / &mut self |
'async_trait (tied to the borrow) |
self, self: Arc<Self>, or no receiver |
'static |
#[responsible]
Apply to an enum. Mark individual variants with #[responsible(ResponseType)] to append a tokio::sync::oneshot::Sender<ResponseType> to that variant's fields.
This forces every caller constructing the variant to create a oneshot channel and pass the sender in, while retaining the receiver to await the response.
Example
use responsible;
Expands to:
Caller pattern
let = ;
sender.send.unwrap;
let result = rx.await.unwrap;
Constraints
- Only tuple (unnamed-field) and unit variants are supported. Named-field variants produce a compile error.
- Multiple
#[responsible]attributes on the same variant — only the first is processed.
License
MIT — see LICENSE.