1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use Future;
/// Receives a value and returns a future that completes once processing finishes.
///
/// This mirrors [`Accepts`](super::Accepts) for asynchronous scenarios where the
/// acceptor must yield until some work is done. The returned future is tied to
/// the lifetime of `self`, making it straightforward to borrow state inside the
/// async body.
///
/// ```rust
/// use accepts::AsyncAccepts;
/// use core::future::Future;
///
/// # use core::task::{Context, Poll};
/// # use std::boxed::Box;
/// #
/// # fn block_on<F: Future<Output = T>, T>(future: F) -> T {
/// # let waker = core::task::Waker::noop();
/// # let mut context = Context::from_waker(&waker);
/// # let mut future = Box::pin(future);
/// # match future.as_mut().poll(&mut context) {
/// # Poll::Ready(output) => output,
/// # Poll::Pending => panic!("Future must complete without suspension in this example"),
/// # }
/// # }
/// #
/// struct AsyncPrinter;
///
/// impl AsyncAccepts<String> for AsyncPrinter {
/// fn accept_async<'a>(&'a self, value: String) -> impl Future<Output = ()> + 'a
/// where
/// String: 'a,
/// {
/// async move {
/// println!("{}", value);
/// }
/// }
/// }
///
/// # block_on(async {
/// let printer = AsyncPrinter;
/// printer
/// .accept_async(String::from("Hello, async world!"))
/// .await;
/// # });
/// ```