poll
import std::future::poll; · source
Types
Poll<T>
type enum Poll<T> {
Ready(T);
Pending;
}
implement enum Poll<T> {
is_ready(&this) -> boolean;
is_pending(&this) -> boolean;
![sink]
into_ready(&this) -> T;
}
The result of one poll call. Pending means "not yet — I have arranged to be woken"; Ready(v) means the value is available and the future is done. into_ready unwraps a Poll you know is ready and panics otherwise, which is what a test driving a future by hand wants.
Variants
| Variant |
|---|
Ready(T) |
Pending |
Methods
is_ready(&this) -> boolean;
is_ready(&this) -> boolean;True when this is Ready. The payload is inspected by reference, so the receiver keeps ownership of it.
is_pending(&this) -> boolean;
is_pending(&this) -> boolean;True when this is Pending.
![sink] into_ready(&this) -> T;
![sink] into_ready(&this) -> T;Move the Ready value out. Aborts on Pending. The compiler's async lowering calls this only after an is_pending check has already returned on the Pending path, so the Pending arm here is a should-never-happen guard rather than a reachable state.
type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type enum Name {
Unit,
Payload(T),
Named { x: i32 },
}An algebraic data type. Variants may be bare or carry a tuple or struct payload, and a match on an enum must cover every variant. Name::Variant names a variant; methods are added with implement enum Name { ... }.
type enum Poll<T> {
Ready(T);
Pending;
}The result of polling a Future: either the final value, or a signal that the value is not ready yet and the task should be re-polled after its Waker fires.
type parameter TPoll::Ready(T)type parameter TPoll::Pendingimplement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
implement enum Name { ... }Names the enum an inherent block extends - the only way to give an enum methods.
language referencetype enum Poll<T> {
Ready(T);
Pending;
}The result of polling a Future: either the final value, or a signal that the value is not ready yet and the task should be re-polled after its Waker fires.
Poll::is_ready(&this) -> booleanTrue when this is Ready. The payload is inspected by reference, so the receiver keeps ownership of it.
&this
mut &this
thisThe receiver of a method. Its first parameter declares how the method takes it: &this borrows read-only, mut &this borrows exclusively, and this / mut this move the value in and consume it. In the body, this.field reaches the members.
Poll::is_pending(&this) -> booleanTrue when this is Pending.
Poll::into_ready(&this) -> TMove the Ready value out. Aborts on Pending. The compiler's async lowering calls this only after an is_pending check has already returned on the Pending path, so the Pending arm here is a should-never-happen guard rather than a reachable state.
type parameter Timport a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
namespace std::future;std::future: stackless async foundations — Future, Poll, Context, Waker, and the drivers that poll them.
Poll::PendingPoll::Ready(T)Poll::into_ready(&this) -> TMove the Ready value out. Aborts on Pending. The compiler's async lowering calls this only after an is_pending check has already returned on the Pending path, so the Pending arm here is a should-never-happen guard rather than a reachable state.
Poll::is_ready(&this) -> booleanTrue when this is Ready. The payload is inspected by reference, so the receiver keeps ownership of it.