Lines Matching full:async
1 …//github.com/dtolnay/async-trait) [![crates-io]](https://crates.io/crates/async-trait) […
9 //! <h5>Type erasure for async trait methods</h5>
11 //! The initial round of stabilizations for the async/await language feature in
12 //! Rust 1.39 did not include support for async fn in traits. Trying to include
13 //! an async fn in a trait produces the following error:
17 //! async fn f() {}
22 //! error[E0706]: trait fns cannot be declared `async`
25 //! 4 | async fn f() {}
29 //! This crate provides an attribute macro to make async fn in traits work.
31 //! Please refer to [*why async fn in traits are hard*][hard] for a deeper
35 //! [hard]: https://smallcultfollowing.com/babysteps/blog/2019/10/26/async-fn-in-traits-are-hard/
42 //! using async fn in a trait.
45 //! top of traits and trait impls that contain async fn, and then they work.
52 //! async fn run(&self);
59 //! async fn run(&self) {
74 //! async fn run(&self) {
84 //! # async fn render_fullscreen(&self) {}
85 //! # async fn hide_for_now(&self) {}
88 //! # async fn remind_user_to_join_mailing_list() {}
91 //! # async fn connect(_media_url: &str) -> Stream { Stream }
93 //! # async fn play(&self) {}
111 //! > ☑ Having async and non-async functions in the same trait;<br>
120 //! Async fns get transformed into methods that return `Pin<Box<dyn Future +
121 //! Send + 'async>>` and delegate to a private async freestanding function.
129 //! fn run<'async>(
130 //! &'async self,
131 //! ) -> Pin<Box<dyn core::future::Future<Output = ()> + Send + 'async>>
133 //! Self: Sync + 'async,
135 //! async fn run(_self: &AutoplayingVideo) {
149 //! Not all async traits need futures that are `dyn Future + Send`. To avoid
150 //! having Send and Sync bounds placed on the async trait methods, invoke the
151 //! async trait macro as `#[async_trait(?Send)]` on both the trait and the impl
158 //! Be aware that async fn syntax does not allow lifetime elision outside of `&`
172 //! async fn test(not_okay: Elided, okay: &usize) {}
180 //! 9 | async fn test(not_okay: Elided, okay: &usize) {}
194 //! async fn test<'e>(elided: Elided<'e>) {}
199 //! async fn test(elided: Elided<'_>) {}
207 //! Traits with async methods can be used as trait objects as long as they meet
216 //! async fn f(&self);
217 //! async fn g(&mut self);
230 //! # async fn f(&self) {}
231 //! # async fn g(&mut self) {}
238 //! The one wrinkle is in traits that provide default implementations of async
245 //! If you make a trait with async methods that have default implementations,
254 //! 8 | async fn cannot_dyn(&self) {}
259 //! implementations for some async methods, there are two resolutions. Either
270 //! async fn can_dyn(&self) {}
291 //! async fn cannot_dyn(&self) where Self: Sized {}