https://github.com/znx3p0/async_t
https://github.com/znx3p0/async_t
Last synced: 22 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/znx3p0/async_t
- Owner: znx3p0
- Created: 2021-11-09T20:38:33.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-18T03:34:40.000Z (almost 3 years ago)
- Last Synced: 2025-04-05T01:11:14.080Z (about 2 months ago)
- Language: Rust
- Size: 27.3 KB
- Stars: 15
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# async_t
This library allows for zero-cost compile-time async-traits.
This library needs nightly and features `generic_associated_types` and `type_alias_impl_trait` to be enabled.
Compiling in stable will automatically use dtolnay's async_trait instead.It supports everything a normal trait would except:
- default async methods
- blanket implementations
- dynamic dispatchIt can also have problems with lifetimes where they have to be specified.
```rust
// spawn example#[async_trait]
trait Spawn {
// supports self, &self, &mut self and no self
async fn spawn() -> JoinHandle<()>;
}#[async_trait]
impl Spawn for Spawner {
async fn spawn() -> JoinHandle<()> {
task::spawn(async {
// ...
})
}
}async fn spawn() -> JoinHandle<()> {
T::spawn().await
}```
```rust
#[async_trait]
trait Sleeper {
#[unsend]
async fn sleep(t: T) -> T;
}#[async_trait]
impl Sleeper for () {
#[unsend]
async fn sleep(t: T) -> T {
task::sleep(Duration::from_secs(2)).await;
t
}
}
```