Merge pull request #180 from harryhaaren/async_in_trait_update

07 workarounds/async in trait: update that nightly has mvp
This commit is contained in:
Eric Holk 2022-12-21 17:30:54 -08:00 committed by GitHub
commit e224ead527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -1,10 +1,10 @@
# `async` in Traits # `async` in Traits
Currently, `async fn` cannot be used in traits. The reasons for this are Currently, `async fn` cannot be used in traits on the stable release of Rust.
somewhat complex, but there are plans to remove this restriction in the Since the 17th November 2022, an MVP of async-fn-in-trait is available on the nightly
future. version of the compiler tool chain, [see here for details](https://blog.rust-lang.org/inside-rust/2022/11/17/async-fn-in-trait-nightly.html).
In the meantime, however, this can be worked around using the In the meantime, there is a work around for the stable tool chain using the
[async-trait crate from crates.io](https://github.com/dtolnay/async-trait). [async-trait crate from crates.io](https://github.com/dtolnay/async-trait).
Note that using these trait methods will result in a heap allocation Note that using these trait methods will result in a heap allocation