maybe-async-rs
maybe-async-rs copied to clipboard
Async traits implementation from nightly
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)
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.
Stabilization update: https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html
Working on this.
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.
Close as solved in 0.2.9.