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:
18 //! async fn f() {}
23 //! error[E0706]: trait fns cannot be declared `async`
26 //! 4 | async fn f() {}
30 //! This crate provides an attribute macro to make async fn in traits work.
32 //! Please refer to [*why async fn in traits are hard*][hard] for a deeper
36 //! [hard]: https://smallcultfollowing.com/babysteps/blog/2019/10/26/async-fn-in-traits-are-hard/
43 //! using async fn in a trait.
46 //! top of traits and trait impls that contain async fn, and then they work.
53 //! async fn run(&self);
60 //! async fn run(&self) {
75 //! async fn run(&self) {
85 //! # async fn render_fullscreen(&self) {}
86 //! # async fn hide_for_now(&self) {}
89 //! # async fn remind_user_to_join_mailing_list() {}
92 //! # async fn connect(_media_url: &str) -> Stream { Stream }
94 //! # async fn play(&self) {}
112 //! > ☑ Having async and non-async functions in the same trait;<br>
121 //! Async fns get transformed into methods that return `Pin<Box<dyn Future +
122 //! Send + 'async_trait>>` and delegate to a private async freestanding function.
136 //! async fn run(_self: &AutoplayingVideo) {
150 //! Not all async traits need futures that are `dyn Future + Send`. To avoid
151 //! having Send and Sync bounds placed on the async trait methods, invoke the
152 //! async trait macro as `#[async_trait(?Send)]` on both the trait and the impl
159 //! Be aware that async fn syntax does not allow lifetime elision outside of `&`
173 //! async fn test(not_okay: Elided, okay: &usize) {}
181 //! 9 | async fn test(not_okay: Elided, okay: &usize) {}
195 //! async fn test<'e>(elided: Elided<'e>) {}
200 //! async fn test(elided: Elided<'_>) {}
208 //! Traits with async methods can be used as trait objects as long as they meet
217 //! async fn f(&self);
218 //! async fn g(&mut self);
231 //! # async fn f(&self) {}
232 //! # async fn g(&mut self) {}
239 //! The one wrinkle is in traits that provide default implementations of async
246 //! If you make a trait with async methods that have default implementations,
255 //! 8 | async fn cannot_dyn(&self) {}
260 //! implementations for some async methods, there are two resolutions. Either
271 //! async fn can_dyn(&self) {}
292 //! async fn cannot_dyn(&self) where Self: Sized {}
307 #![doc(html_root_url = "https://docs.rs/async-trait/0.1.74")]