pub enum Poll<T> {
    Ready(T),
    Pending,
}
Expand description

Indicates whether a value is available or if the current task has been scheduled to receive a wakeup instead.

Variants§

§

Ready(T)

Represents that a value is immediately ready.

§

Pending

Represents that a value is not ready yet.

When a function returns Pending, the function must also ensure that the current task is scheduled to be awoken when progress can be made.

Implementations§

Maps a Poll<T> to Poll<U> by applying a function to a contained value.

Examples

Converts a Poll<String> into a Poll<usize>, consuming the original:

let poll_some_string = Poll::Ready(String::from("Hello, World!"));
// `Poll::map` takes self *by value*, consuming `poll_some_string`
let poll_some_len = poll_some_string.map(|s| s.len());

assert_eq!(poll_some_len, Poll::Ready(13));

Returns true if the poll is a Poll::Ready value.

Examples
let x: Poll<u32> = Poll::Ready(2);
assert_eq!(x.is_ready(), true);

let x: Poll<u32> = Poll::Pending;
assert_eq!(x.is_ready(), false);

Returns true if the poll is a Pending value.

Examples
let x: Poll<u32> = Poll::Ready(2);
assert_eq!(x.is_pending(), false);

let x: Poll<u32> = Poll::Pending;
assert_eq!(x.is_pending(), true);
🔬This is a nightly-only experimental API. (poll_ready)

Extracts the successful type of a Poll<T>.

When combined with the ? operator, this function will propagate any Poll::Pending values to the caller, and extract the T from Poll::Ready.

Examples
#![feature(poll_ready)]

use std::task::{Context, Poll};
use std::future::{self, Future};
use std::pin::Pin;

pub fn do_poll(cx: &mut Context<'_>) -> Poll<()> {
    let mut fut = future::ready(42);
    let fut = Pin::new(&mut fut);

    let num = fut.poll(cx).ready()?;
    // ... use num

    Poll::Ready(())
}

Maps a Poll<Result<T, E>> to Poll<Result<U, E>> by applying a function to a contained Poll::Ready(Ok) value, leaving all other variants untouched.

This function can be used to compose the results of two functions.

Examples
let res: Poll<Result<u8, _>> = Poll::Ready("12".parse());
let squared = res.map_ok(|n| n * n);
assert_eq!(squared, Poll::Ready(Ok(144)));

Maps a Poll::Ready<Result<T, E>> to Poll::Ready<Result<T, F>> by applying a function to a contained Poll::Ready(Err) value, leaving all other variants untouched.

This function can be used to pass through a successful result while handling an error.

Examples
let res: Poll<Result<u8, _>> = Poll::Ready("oops".parse());
let res = res.map_err(|_| 0_u8);
assert_eq!(res, Poll::Ready(Err(0)));

Maps a Poll<Option<Result<T, E>>> to Poll<Option<Result<U, E>>> by applying a function to a contained Poll::Ready(Some(Ok)) value, leaving all other variants untouched.

This function can be used to compose the results of two functions.

Examples
let res: Poll<Option<Result<u8, _>>> = Poll::Ready(Some("12".parse()));
let squared = res.map_ok(|n| n * n);
assert_eq!(squared, Poll::Ready(Some(Ok(144))));

Maps a Poll::Ready<Option<Result<T, E>>> to Poll::Ready<Option<Result<T, F>>> by applying a function to a contained Poll::Ready(Some(Err)) value, leaving all other variants untouched.

This function can be used to pass through a successful result while handling an error.

Examples
let res: Poll<Option<Result<u8, _>>> = Poll::Ready(Some("oops".parse()));
let res = res.map_err(|_| 0_u8);
assert_eq!(res, Poll::Ready(Some(Err(0))));

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Moves the value into a Poll::Ready to make a Poll<T>.

Example
assert_eq!(Poll::from(true), Poll::Ready(true));
🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value produced by ? when not short-circuiting.
🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value passed to FromResidual::from_residual as part of ? when short-circuiting. Read more
🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from its Output type. Read more
🔬This is a nightly-only experimental API. (try_trait_v2)
Used in ? to decide whether the operator should produce a value (because this returned ControlFlow::Continue) or propagate a value back to the caller (because this returned ControlFlow::Break). Read more
🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value produced by ? when not short-circuiting.
🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value passed to FromResidual::from_residual as part of ? when short-circuiting. Read more
🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from its Output type. Read more
🔬This is a nightly-only experimental API. (try_trait_v2)
Used in ? to decide whether the operator should produce a value (because this returned ControlFlow::Continue) or propagate a value back to the caller (because this returned ControlFlow::Break). Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
TODO: once 1.33.0 is the minimum supported compiler version, remove Any::type_id_compat and use StdAny::type_id instead. https://github.com/rust-lang/rust/issues/27745
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Deserializes using the given deserializer
Compare self to key and return true if they are equal.
Converts to this type from the input type.

Returns the argument unchanged.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Attaches the current Context to this type, returning a WithContext wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type for metadata in pointers and references to Self.
Should always be Self
Performance hack: Clone doesn’t get inlined for Copy types in debug mode, so make it inline anyway.
Tests if Self the same as the type T Read more
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
upcast ref
upcast mut ref
upcast boxed dyn
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more