#[repr(C)]pub struct Task<S, F: Future, STO> { /* private fields */ }
Expand description
A task.
This type contains the various components of a task: the future
itself, the task’s header, and a reference to the task’s scheduler. When a
task is spawned, the Task
type is placed on the heap (or wherever spawned
tasks are stored), and a type-erased TaskRef
that points to that Task
is returned. Once a task is spawned, it is primarily interacted with via
TaskRef
s.
§Vtables and Type Erasure
The Task
struct, once spawned, is rarely interacted with directly. Because
a system may spawn any number of different Future
types as tasks, and
may potentially also contain multiple types of scheduler and/or task
storage, the scheduler and other parts of the system generally interact
with tasks via type-erased TaskRef
s.
However, in order to actually poll a task’s Future
, or perform other
operations such as deallocating a task, it is necessary to know the type of
the the task’s Future
(and potentially, that of the scheduler and/or
storage). Therefore, operations that are specific to the task’s S
-typed
scheduler, F
-typed Future
, and STO
-typed Storage
are performed
via dynamic dispatch.