Skip to content

Commit

Permalink
example
Browse files Browse the repository at this point in the history
Signed-off-by: Yoshua Wuyts <[email protected]>
  • Loading branch information
yoshuawuyts committed Sep 29, 2019
1 parent 722b354 commit d7e8b2d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/future/into_future.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
use crate::future::Future;

/// Convert a type into a `Future`.
///
/// # Examples
///
/// ```
/// use async_std::future::{Future, IntoFuture};
/// use async_std::io;
/// use async_std::pin::Pin;
///
/// struct Client;
///
/// impl Client {
/// pub async fn send(self) -> io::Result<()> {
/// // Send a request
/// Ok(())
/// }
/// }
///
/// impl IntoFuture for Client {
/// type Output = io::Result<()>;
///
/// type Future = Pin<Box<dyn Future<Output = Self::Output>>>;
///
/// fn into_future(self) -> Self::Future {
/// Box::pin(async {
/// self.send().await
/// })
/// }
/// }
/// ```
pub trait IntoFuture {
/// The type of value produced on completion.
type Output;
Expand Down

0 comments on commit d7e8b2d

Please sign in to comment.