-
-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy patheither.rs
More file actions
47 lines (41 loc) · 960 Bytes
/
Copy patheither.rs
File metadata and controls
47 lines (41 loc) · 960 Bytes
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
39
40
41
42
43
44
45
46
47
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
use pin_project_lite::pin_project;
pin_project! {
/// One of two possible futures that have the same output type.
#[project = EitherProj]
pub(crate) enum Either<F1, F2> {
Left {
#[pin]
fut: F1
},
Right {
#[pin]
fut: F2,
},
}
}
impl<F1, F2> Either<F1, F2> {
pub(crate) fn left(fut: F1) -> Self {
Either::Left { fut }
}
pub(crate) fn right(fut: F2) -> Self {
Either::Right { fut }
}
}
impl<F1, F2> Future for Either<F1, F2>
where
F1: Future,
F2: Future<Output = F1::Output>,
{
type Output = F1::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.project() {
EitherProj::Left { fut } => fut.poll(cx),
EitherProj::Right { fut } => fut.poll(cx),
}
}
}