async-trait-static

Crates.ioasync-trait-static
lib.rsasync-trait-static
version0.1.4
sourcesrc
created_at2020-03-16 15:45:14.615591
updated_at2021-01-12 10:14:00.188143
descriptionasync fn in trait for no_std
homepage
repositoryhttps://github.com/tiannian/async-trait-static
max_upload_size
id219505
size19,204
(tiannian)

documentation

README

Async trait methods for no_std

Features 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

Support syntax

  • async in trait. #[async_trait].
  • impl trait as return in trait. #[ritit].

Features Status

  • Self
    • Self by reference.
    • Self by value.
    • Self by mut reference.
    • no Self.
    • any type of Self. (need test)
    • Self by mut value. (It seems unuse)
  • Any number of arguments, any return value.
    • Arguments.
      • As value.
      • As reference without lifetime.
    • Return value expect reference (return reference at Lifetime return). (need test)
  • Lifetime parameters. (need test)
    • Lifetime arguments.
    • Lifetime return.
  • Associated types support. (need test)
  • Having async and non-async functions in the same trait.
  • support default async fn implementations in trait.
  • Generic type parameters.
    • Generic arguments.
    • Generic return. (need implement)
    • impl trait in arguments. (need implement)

Usage

Please enable feature type_alias_impl_trait and generic_associated_types;

async_trait

#![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;
    }
}

ritit

#![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;
        }
    }
}
Commit count: 35

cargo fmt