]>
git.proxmox.com Git - rustc.git/blob - src/libcore/task/poll.rs
1 #![stable(feature = "futures_api", since = "1.36.0")]
4 use crate::result
::Result
;
6 /// Indicates whether a value is available or if the current task has been
7 /// scheduled to receive a wakeup instead.
8 #[must_use = "this `Poll` may be a `Pending` variant, which should be handled"]
9 #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
10 #[stable(feature = "futures_api", since = "1.36.0")]
12 /// Represents that a value is immediately ready.
13 #[stable(feature = "futures_api", since = "1.36.0")]
15 #[stable(feature = "futures_api", since = "1.36.0")]
19 /// Represents that a value is not ready yet.
21 /// When a function returns `Pending`, the function *must* also
22 /// ensure that the current task is scheduled to be awoken when
23 /// progress can be made.
24 #[stable(feature = "futures_api", since = "1.36.0")]
29 /// Changes the ready value of this `Poll` with the closure provided.
30 #[stable(feature = "futures_api", since = "1.36.0")]
31 pub fn map
<U
, F
>(self, f
: F
) -> Poll
<U
>
32 where F
: FnOnce(T
) -> U
35 Poll
::Ready(t
) => Poll
::Ready(f(t
)),
36 Poll
::Pending
=> Poll
::Pending
,
40 /// Returns `true` if this is `Poll::Ready`
42 #[stable(feature = "futures_api", since = "1.36.0")]
43 pub fn is_ready(&self) -> bool
{
45 Poll
::Ready(_
) => true,
46 Poll
::Pending
=> false,
50 /// Returns `true` if this is `Poll::Pending`
52 #[stable(feature = "futures_api", since = "1.36.0")]
53 pub fn is_pending(&self) -> bool
{
58 impl<T
, E
> Poll
<Result
<T
, E
>> {
59 /// Changes the success value of this `Poll` with the closure provided.
60 #[stable(feature = "futures_api", since = "1.36.0")]
61 pub fn map_ok
<U
, F
>(self, f
: F
) -> Poll
<Result
<U
, E
>>
62 where F
: FnOnce(T
) -> U
65 Poll
::Ready(Ok(t
)) => Poll
::Ready(Ok(f(t
))),
66 Poll
::Ready(Err(e
)) => Poll
::Ready(Err(e
)),
67 Poll
::Pending
=> Poll
::Pending
,
71 /// Changes the error value of this `Poll` with the closure provided.
72 #[stable(feature = "futures_api", since = "1.36.0")]
73 pub fn map_err
<U
, F
>(self, f
: F
) -> Poll
<Result
<T
, U
>>
74 where F
: FnOnce(E
) -> U
77 Poll
::Ready(Ok(t
)) => Poll
::Ready(Ok(t
)),
78 Poll
::Ready(Err(e
)) => Poll
::Ready(Err(f(e
))),
79 Poll
::Pending
=> Poll
::Pending
,
84 #[stable(feature = "futures_api", since = "1.36.0")]
85 impl<T
> From
<T
> for Poll
<T
> {
86 fn from(t
: T
) -> Poll
<T
> {
91 #[stable(feature = "futures_api", since = "1.36.0")]
92 impl<T
, E
> Try
for Poll
<Result
<T
, E
>> {
97 fn into_result(self) -> Result
<Self::Ok
, Self::Error
> {
99 Poll
::Ready(Ok(x
)) => Ok(Poll
::Ready(x
)),
100 Poll
::Ready(Err(e
)) => Err(e
),
101 Poll
::Pending
=> Ok(Poll
::Pending
),
106 fn from_error(e
: Self::Error
) -> Self {
111 fn from_ok(x
: Self::Ok
) -> Self {
116 #[stable(feature = "futures_api", since = "1.36.0")]
117 impl<T
, E
> Try
for Poll
<Option
<Result
<T
, E
>>> {
118 type Ok
= Poll
<Option
<T
>>;
122 fn into_result(self) -> Result
<Self::Ok
, Self::Error
> {
124 Poll
::Ready(Some(Ok(x
))) => Ok(Poll
::Ready(Some(x
))),
125 Poll
::Ready(Some(Err(e
))) => Err(e
),
126 Poll
::Ready(None
) => Ok(Poll
::Ready(None
)),
127 Poll
::Pending
=> Ok(Poll
::Pending
),
132 fn from_error(e
: Self::Error
) -> Self {
133 Poll
::Ready(Some(Err(e
)))
137 fn from_ok(x
: Self::Ok
) -> Self {