maybe-async-rs icon indicating copy to clipboard operation
maybe-async-rs copied to clipboard

Async traits implementation from nightly

Open Niederb opened this issue 2 years ago • 2 comments

This crate currently uses the async_trait crate to support async functions in traits. My understanding of async is not very deep but I wonder if it would be possible to use the implementation that is available on nightly instead? (see https://blog.rust-lang.org/inside-rust/2022/11/17/async-fn-in-trait-nightly.html)

Niederb avatar Apr 13 '23 06:04 Niederb

This is indeed posiible. However the async fn in trait RFC is still in early development and not stablized yet, so I think it more appropriate to add a feature gate to do so.

fMeow avatar Apr 14 '23 07:04 fMeow

Stabilization update: https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html

dtolnay avatar Jan 15 '24 18:01 dtolnay

Working on this.

fMeow avatar Jan 30 '24 12:01 fMeow

I released 0.2.9 which add async fn in traits support. For compatibilty reason, a AFIT flag is used to indicate a native async fn in traits. So the api is like the following:

#[maybe_async::maybe_async(AFIT)]
trait A {
    async fn async_fn_in_trait() -> Result<(), ()>;
}

struct Foo;

#[maybe_async::maybe_async(AFIT)]
impl A for Foo {
    async fn async_fn_in_trait() -> Result<(), ()> {
        Ok(())
    }
}

It will become the default in the future major release, but not for now.

fMeow avatar Jan 31 '24 04:01 fMeow

Close as solved in 0.2.9.

fMeow avatar Feb 02 '24 02:02 fMeow