12
12
reason = "futures in libcore are unstable" ,
13
13
issue = "50547" ) ]
14
14
15
+ use ops:: Try ;
16
+ use result:: Result ;
17
+
15
18
/// Indicates whether a value is available or if the current task has been
16
19
/// scheduled to receive a wakeup instead.
17
20
#[ derive( Copy , Clone , Debug , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
@@ -39,6 +42,7 @@ impl<T> Poll<T> {
39
42
}
40
43
41
44
/// Returns whether this is `Poll::Ready`
45
+ #[ inline]
42
46
pub fn is_ready ( & self ) -> bool {
43
47
match * self {
44
48
Poll :: Ready ( _) => true ,
@@ -47,6 +51,7 @@ impl<T> Poll<T> {
47
51
}
48
52
49
53
/// Returns whether this is `Poll::Pending`
54
+ #[ inline]
50
55
pub fn is_pending ( & self ) -> bool {
51
56
!self . is_ready ( )
52
57
}
@@ -81,3 +86,52 @@ impl<T> From<T> for Poll<T> {
81
86
Poll :: Ready ( t)
82
87
}
83
88
}
89
+
90
+ impl < T , E > Try for Poll < Result < T , E > > {
91
+ type Ok = Poll < T > ;
92
+ type Error = E ;
93
+
94
+ #[ inline]
95
+ fn into_result ( self ) -> Result < Self :: Ok , Self :: Error > {
96
+ match self {
97
+ Poll :: Ready ( Ok ( x) ) => Ok ( Poll :: Ready ( x) ) ,
98
+ Poll :: Ready ( Err ( e) ) => Err ( e) ,
99
+ Poll :: Pending => Ok ( Poll :: Pending ) ,
100
+ }
101
+ }
102
+
103
+ #[ inline]
104
+ fn from_error ( e : Self :: Error ) -> Self {
105
+ Poll :: Ready ( Err ( e) )
106
+ }
107
+
108
+ #[ inline]
109
+ fn from_ok ( x : Self :: Ok ) -> Self {
110
+ x. map ( Ok )
111
+ }
112
+ }
113
+
114
+ impl < T , E > Try for Poll < Option < Result < T , E > > > {
115
+ type Ok = Poll < Option < T > > ;
116
+ type Error = E ;
117
+
118
+ #[ inline]
119
+ fn into_result ( self ) -> Result < Self :: Ok , Self :: Error > {
120
+ match self {
121
+ Poll :: Ready ( Some ( Ok ( x) ) ) => Ok ( Poll :: Ready ( Some ( x) ) ) ,
122
+ Poll :: Ready ( Some ( Err ( e) ) ) => Err ( e) ,
123
+ Poll :: Ready ( None ) => Ok ( Poll :: Ready ( None ) ) ,
124
+ Poll :: Pending => Ok ( Poll :: Pending ) ,
125
+ }
126
+ }
127
+
128
+ #[ inline]
129
+ fn from_error ( e : Self :: Error ) -> Self {
130
+ Poll :: Ready ( Some ( Err ( e) ) )
131
+ }
132
+
133
+ #[ inline]
134
+ fn from_ok ( x : Self :: Ok ) -> Self {
135
+ x. map ( |x| x. map ( Ok ) )
136
+ }
137
+ }
0 commit comments