1212 reason = "futures in libcore are unstable" ,
1313 issue = "50547" ) ]
1414
15+ use ops:: Try ;
16+ use result:: Result ;
17+
1518/// Indicates whether a value is available or if the current task has been
1619/// scheduled to receive a wakeup instead.
1720#[ derive( Copy , Clone , Debug , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
@@ -39,6 +42,7 @@ impl<T> Poll<T> {
3942 }
4043
4144 /// Returns whether this is `Poll::Ready`
45+ #[ inline]
4246 pub fn is_ready ( & self ) -> bool {
4347 match * self {
4448 Poll :: Ready ( _) => true ,
@@ -47,6 +51,7 @@ impl<T> Poll<T> {
4751 }
4852
4953 /// Returns whether this is `Poll::Pending`
54+ #[ inline]
5055 pub fn is_pending ( & self ) -> bool {
5156 !self . is_ready ( )
5257 }
@@ -81,3 +86,52 @@ impl<T> From<T> for Poll<T> {
8186 Poll :: Ready ( t)
8287 }
8388}
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