async-trait-static 0.1.3

async fn in trait for no_std
Documentation

Async trait methods for no_std

Features like async-trait, avoid using Box and dyn.

This crate is ready for #![no_std] when PR69033 merged.

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.

Features

  • Self
    • Self by reference.
    • Self by value.
    • Self by mut reference.
    • no Self.
    • any type of Self.
  • Any number of arguments, any return value.
    • Arguments.
      • As value.
      • As reference without lifetime.
    • Return value expect reference (return reference at Lifetime return).
  • Lifetime parameters.
    • Lifetime arguments.
    • Lifetime return.
  • Associated types support.
  • Having async and non-async functions in the same trait.

Incomplete Feature

These feature all require generic_associated_types support type arguments.

Following issue: #44265

  • support default async fn implementations in trait (Wait feature generic_associated_types support type arguments).
  • Generic type parameters.
    • Generic arguments (Wait for feature generic_associated_types support type arguments).
    • Generic return (Wait for feature generic_associated_types support type arguments).
    • impl trait in arguments (Wait for feature generic_associated_types support type arguments).

Usage

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;
    }
}