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
use crate::future::Future;

/// 转换为 `Future`。
#[unstable(feature = "into_future", issue = "67644")]
pub trait IntoFuture {
    /// future 完成时将产生的输出。
    #[unstable(feature = "into_future", issue = "67644")]
    type Output;

    /// 我们要把它变成哪种 future?
    #[unstable(feature = "into_future", issue = "67644")]
    type Future: Future<Output = Self::Output>;

    /// 根据一个值创建一个 future。
    #[unstable(feature = "into_future", issue = "67644")]
    fn into_future(self) -> Self::Future;
}

#[unstable(feature = "into_future", issue = "67644")]
impl<F: Future> IntoFuture for F {
    type Output = F::Output;
    type Future = F;

    fn into_future(self) -> Self::Future {
        self
    }
}