ready
import std::future::ready; · source
Types
Ready<T>
type struct Ready<T> {
value: Option<T>;
static new(value: T) -> Ready<T>;
}
Ready::new(value) is a future that completes immediately — useful for testing and for satisfying a Future bound with a value you already have.
Properties
| Property | Type |
|---|---|
value | Option<T> |
Constructors
static new(value: T) -> Ready<T>;
PendingThenReady<T>
type struct PendingThenReady<T> {
remaining: u32;
value: Option<T>;
static new(pending_count: u32, value: T) -> PendingThenReady<T>;
}
PendingThenReady::new(n, value) returns Pending for the first n polls, waking itself each time, then completes — the simplest way to exercise an executor's re-scheduling path in a test.
Both panic if polled again after completing.
Properties
| Property | Type |
|---|---|
remaining | u32 |
value | Option<T> |
Constructors
static new(pending_count: u32, value: T) -> PendingThenReady<T>;
Trait implementations
Ready
implement<T> trait Future<T> for struct Ready<T>
PendingThenReady
implement<T> trait Future<T> for struct PendingThenReady<T>
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 struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct Ready<T> {
value: Option<T>;
}A future that is already complete: the first poll returns Ready(value). The value is held in an Option and moved out on completion, so polling a Ready a second time is a contract violation (it panics) rather than a double-move.
type parameter TReady.value: Option<T>type parameter Tstatic name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
static Ready::new(value: T) -> Ready<T>(parameter) value: Ttype struct Ready<T> {
value: Option<T>;
}A future that is already complete: the first poll returns Ready(value). The value is held in an Option and moved out on completion, so polling a Ready a second time is a contract violation (it panics) rather than a double-move.
type struct PendingThenReady<T> {
remaining: u32;
value: Option<T>;
}A future that reports Pending for its first pending_count polls and then completes with value. Exercises the suspend/resume path end-to-end under a driver without any I/O or threads — the canonical Phase-1 validation future.
PendingThenReady.remaining: u32PendingThenReady.value: Option<T>type parameter Tstatic PendingThenReady::new(pending_count: u32, value: T) -> PendingThenReady<T>(parameter) pending_count: u32type struct PendingThenReady<T> {
remaining: u32;
value: Option<T>;
}A future that reports Pending for its first pending_count polls and then completes with value. Exercises the suspend/resume path end-to-end under a driver without any I/O or threads — the canonical Phase-1 validation future.
import 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.
namespace std::future::ready;Hand-written sample futures: Ready<T> and PendingThenReady<T>.
static Ready::new(value: T) -> Ready<T>Ready.value: Option<T>type trait Future {
type Output;
poll(mut &this, cx: Context*) -> Poll<This::Output>;
}An asynchronous computation. poll drives it one step: Ready(v) when the value is available, Pending when it is not yet (the future has arranged, via cx's waker, to be polled again later).
static PendingThenReady::new(pending_count: u32, value: T) -> PendingThenReady<T>Poll::PendingPendingThenReady.remaining: u32implement 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.
type trait Name : Base {
method(&this, other: &This) -> Ret;
}Names a set of methods a type may implement. Inside the body This is the implementing type; methods may carry default bodies, and a trait may require a base trait (type trait Ord : Eq). Generic code asks for a trait with where T: Name.
implement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language reference