-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathinto_future.rs
38 lines (30 loc) · 1.13 KB
/
into_future.rs
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
use core::future::Future;
use crate::utils::MaybeDone;
/// Conversion into a `Future`.
pub trait IntoFuture {
/// The output that the future will produce on completion.
type Output;
/// Which kind of future are we turning this into?
type IntoFuture: Future<Output = Self::Output>;
/// Creates a future from a value.
fn into_future(self) -> Self::IntoFuture;
}
/// TODO: in the std impl, make the bound `Fut: IntoFuture`.
impl<Fut: Future> IntoFuture for Vec<Fut> {
type Output = Vec<Fut::Output>;
type IntoFuture = crate::future::join::vec::Join<Fut>;
fn into_future(self) -> Self::IntoFuture {
use crate::future::join::vec::Join;
Join::new(self.into_iter().collect())
}
}
/// TODO: in the std impl, make the bound `Fut: IntoFuture`.
impl<Fut: Future, const N: usize> IntoFuture for [Fut; N] {
type Output = [Fut::Output; N];
type IntoFuture = crate::future::join::array::Join<Fut, N>;
fn into_future(self) -> Self::IntoFuture {
crate::future::join::array::Join {
elems: self.map(|fut| MaybeDone::new(core::future::IntoFuture::into_future(fut))),
}
}
}