| Crates.io | async-trait-static |
| lib.rs | async-trait-static |
| version | 0.1.4 |
| created_at | 2020-03-16 15:45:14.615591+00 |
| updated_at | 2021-01-12 10:14:00.188143+00 |
| description | async fn in trait for no_std |
| homepage | |
| repository | https://github.com/tiannian/async-trait-static |
| max_upload_size | |
| id | 219505 |
| size | 19,204 |
no_stdFeatures like async-trait, avoid using Box and dyn. You can use async keywork in trait without alloc.
Thanks to crate async-trait, some code from these.
WARNING: This crate use some unstable even incomplete feature. You will get some warning from compiler.
If you want to use crate, please add #![feature(type_alias_impl_trait)] and #![feature(generic_associated_types)]
to you crate's root file.
This crate support async in trait through #[async_trait] and sup
async in trait. #[async_trait].impl trait as return in trait. #[ritit].Self
Self by reference.Self by value.Self by mut reference.Self.Self. (need test)Self by mut value. (It seems unuse)Lifetime return). (need test)async fn implementations in trait.impl trait in arguments. (need implement)Please enable feature type_alias_impl_trait and generic_associated_types;
#![feature(type_alias_impl_trait)]
#![feature(generic_associated_types)]
use async_trait_static::async_trait;
async fn hello() -> u8 {
1
}
#[async_trait]
trait AsyncFnTrait {
async fn run(&self);
}
struct AsyncStruct;
#[async_trait]
impl AsyncFnTrait for AsyncStruct {
async fn run(&self) {
hello().await;
}
}
#![feature(type_alias_impl_trait)]
#![feature(generic_associated_types)]
use async_trait_static::ritit;
#[ritit]
trait AsyncFnTrait {
fn run<T: Clone>(&self, t: T) -> impl core::future::Future<Output = ()>;
fn deff(&self) -> impl core::future::Future<Output = u8> {
async move { 1 }
}
}
struct AsyncStruct;
impl AsyncStruct {
async fn hello(&self) -> u8 {
1
}
}
#[ritit]
impl AsyncFnTrait for AsyncStruct {
fn run<T: Clone>(&self, t: T) -> impl core::future::Future<Output = ()> {
async move {
self.hello().await;
}
}
}