Skip to content

Commit d7e8b2d

Browse files
committed
example
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent 722b354 commit d7e8b2d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/future/into_future.rs

+29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
use crate::future::Future;
22

33
/// Convert a type into a `Future`.
4+
///
5+
/// # Examples
6+
///
7+
/// ```
8+
/// use async_std::future::{Future, IntoFuture};
9+
/// use async_std::io;
10+
/// use async_std::pin::Pin;
11+
///
12+
/// struct Client;
13+
///
14+
/// impl Client {
15+
/// pub async fn send(self) -> io::Result<()> {
16+
/// // Send a request
17+
/// Ok(())
18+
/// }
19+
/// }
20+
///
21+
/// impl IntoFuture for Client {
22+
/// type Output = io::Result<()>;
23+
///
24+
/// type Future = Pin<Box<dyn Future<Output = Self::Output>>>;
25+
///
26+
/// fn into_future(self) -> Self::Future {
27+
/// Box::pin(async {
28+
/// self.send().await
29+
/// })
30+
/// }
31+
/// }
32+
/// ```
433
pub trait IntoFuture {
534
/// The type of value produced on completion.
635
type Output;

0 commit comments

Comments
 (0)