@@ -32,6 +32,61 @@ pub enum Poll<T> {
32
32
Pending ,
33
33
}
34
34
35
+ impl < T > Poll < T > {
36
+ /// Change the ready value of this `Poll` with the closure provided
37
+ pub fn map < U , F > ( self , f : F ) -> Poll < U >
38
+ where F : FnOnce ( T ) -> U
39
+ {
40
+ match self {
41
+ Poll :: Ready ( t) => Poll :: Ready ( f ( t) ) ,
42
+ Poll :: Pending => Poll :: Pending ,
43
+ }
44
+ }
45
+
46
+ /// Returns whether this is `Poll::Ready`
47
+ pub fn is_ready ( & self ) -> bool {
48
+ match * self {
49
+ Poll :: Ready ( _) => true ,
50
+ Poll :: Pending => false ,
51
+ }
52
+ }
53
+
54
+ /// Returns whether this is `Poll::Pending`
55
+ pub fn is_pending ( & self ) -> bool {
56
+ !self . is_ready ( )
57
+ }
58
+ }
59
+
60
+ impl < T , E > Poll < Result < T , E > > {
61
+ /// Change the success value of this `Poll` with the closure provided
62
+ pub fn map_ok < U , F > ( self , f : F ) -> Poll < Result < U , E > >
63
+ where F : FnOnce ( T ) -> U
64
+ {
65
+ match self {
66
+ Poll :: Ready ( Ok ( t) ) => Poll :: Ready ( Ok ( f ( t) ) ) ,
67
+ Poll :: Ready ( Err ( e) ) => Poll :: Ready ( Err ( e) ) ,
68
+ Poll :: Pending => Poll :: Pending ,
69
+ }
70
+ }
71
+
72
+ /// Change the error value of this `Poll` with the closure provided
73
+ pub fn map_err < U , F > ( self , f : F ) -> Poll < Result < T , U > >
74
+ where F : FnOnce ( E ) -> U
75
+ {
76
+ match self {
77
+ Poll :: Ready ( Ok ( t) ) => Poll :: Ready ( Ok ( t) ) ,
78
+ Poll :: Ready ( Err ( e) ) => Poll :: Ready ( Err ( f ( e) ) ) ,
79
+ Poll :: Pending => Poll :: Pending ,
80
+ }
81
+ }
82
+ }
83
+
84
+ impl < T > From < T > for Poll < T > {
85
+ fn from ( t : T ) -> Poll < T > {
86
+ Poll :: Ready ( t)
87
+ }
88
+ }
89
+
35
90
/// A `Waker` is a handle for waking up a task by notifying its executor that it
36
91
/// is ready to be run.
37
92
///
0 commit comments