9
9
10
10
//! Some utilities to make working with the standard library's [`Future`]s easier
11
11
12
- use crate :: events:: ReplayEvent ;
13
12
use crate :: prelude:: * ;
14
13
use core:: future:: Future ;
15
14
use core:: marker:: Unpin ;
16
15
use core:: pin:: Pin ;
17
16
use core:: task:: { Context , Poll } ;
18
17
19
- enum EventFuture < F : Future < Output = Result < ( ) , ReplayEvent > > > {
18
+ enum ResultFuture < F : Future < Output = Result < ( ) , E > > , E : Copy + Unpin > {
20
19
Pending ( F ) ,
21
- Ready ( Result < ( ) , ReplayEvent > ) ,
20
+ Ready ( Result < ( ) , E > ) ,
22
21
}
23
22
24
- pub ( crate ) struct MultiEventFuturePoller < F : Future < Output = Result < ( ) , ReplayEvent > > + Unpin > {
25
- futures_state : Vec < EventFuture < F > > ,
23
+ pub ( crate ) struct MultiResultFuturePoller <
24
+ F : Future < Output = Result < ( ) , E > > + Unpin ,
25
+ E : Copy + Unpin ,
26
+ > {
27
+ futures_state : Vec < ResultFuture < F , E > > ,
26
28
}
27
29
28
- impl < F : Future < Output = Result < ( ) , ReplayEvent > > + Unpin > MultiEventFuturePoller < F > {
30
+ impl < F : Future < Output = Result < ( ) , E > > + Unpin , E : Copy + Unpin > MultiResultFuturePoller < F , E > {
29
31
pub fn new ( futures : Vec < F > ) -> Self {
30
- let futures_state = futures. into_iter ( ) . map ( |f| EventFuture :: Pending ( f) ) . collect ( ) ;
32
+ let futures_state = futures. into_iter ( ) . map ( |f| ResultFuture :: Pending ( f) ) . collect ( ) ;
31
33
Self { futures_state }
32
34
}
33
35
}
34
36
35
- impl < F : Future < Output = Result < ( ) , ReplayEvent > > + Unpin > Future for MultiEventFuturePoller < F > {
36
- type Output = Vec < Result < ( ) , ReplayEvent > > ;
37
- fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Vec < Result < ( ) , ReplayEvent > > > {
37
+ impl < F : Future < Output = Result < ( ) , E > > + Unpin , E : Copy + Unpin > Future
38
+ for MultiResultFuturePoller < F , E >
39
+ {
40
+ type Output = Vec < Result < ( ) , E > > ;
41
+ fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Vec < Result < ( ) , E > > > {
38
42
let mut have_pending_futures = false ;
39
43
let futures_state = & mut self . get_mut ( ) . futures_state ;
40
44
for state in futures_state. iter_mut ( ) {
41
45
match state {
42
- EventFuture :: Pending ( ref mut fut) => match Pin :: new ( fut) . poll ( cx) {
46
+ ResultFuture :: Pending ( ref mut fut) => match Pin :: new ( fut) . poll ( cx) {
43
47
Poll :: Ready ( res) => {
44
- * state = EventFuture :: Ready ( res) ;
48
+ * state = ResultFuture :: Ready ( res) ;
45
49
} ,
46
50
Poll :: Pending => {
47
51
have_pending_futures = true ;
48
52
} ,
49
53
} ,
50
- EventFuture :: Ready ( _) => continue ,
54
+ ResultFuture :: Ready ( _) => continue ,
51
55
}
52
56
}
53
57
@@ -57,8 +61,8 @@ impl<F: Future<Output = Result<(), ReplayEvent>> + Unpin> Future for MultiEventF
57
61
let results = futures_state
58
62
. iter ( )
59
63
. filter_map ( |e| match e {
60
- EventFuture :: Ready ( res) => Some ( res) ,
61
- EventFuture :: Pending ( _) => {
64
+ ResultFuture :: Ready ( res) => Some ( res) ,
65
+ ResultFuture :: Pending ( _) => {
62
66
debug_assert ! (
63
67
false ,
64
68
"All futures are expected to be ready if none are pending"
0 commit comments