pub trait IntoFuture {
    type Output;
    type Future: Future<Output = Self::Output>;

    // Required method
    fn into_future(self) -> Self::Future;
}
Expand description

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
        })
    }
}

Required Associated Types§

source

type Output

The type of value produced on completion.

source

type Future: Future<Output = Self::Output>

Which kind of future are we turning this into?

Required Methods§

source

fn into_future(self) -> Self::Future

Create a future from a value

Implementors§

source§

impl<T> IntoFuture for T
where T: Future,

§

type Output = <T as Future>::Output

§

type Future = T