maitake::task

Struct Task

Source
#[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 TaskRefs.

§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 TaskRefs.

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.

Implementations§

Source§

impl<S, F, STO> Task<S, F, STO>
where S: Schedule + 'static, F: Future, STO: Storage<S, F>,

Source

pub fn new(future: F) -> Self

Create a new (non-heap-allocated) Task.

This needs to be heap allocated using an implementor of the Storage trait to be used with the scheduler.

Source

pub fn id(&self) -> TaskId

Returns a TaskId that uniquely identifies this task.

The returned ID does not increment the task’s reference count, and may persist even after the task it identifies has completed and been deallocated.

Trait Implementations§

Source§

impl<S, F, STO> Debug for Task<S, F, STO>
where F: Future,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S, F, STO> Drop for Task<S, F, STO>
where F: Future,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<S, F, STO> Send for Task<S, F, STO>
where S: Send, F: Future + Send,

Source§

impl<S, F, STO> Sync for Task<S, F, STO>
where S: Sync, F: Future + Sync,

Auto Trait Implementations§

§

impl<S, F, STO> !Freeze for Task<S, F, STO>

§

impl<S, F, STO> !RefUnwindSafe for Task<S, F, STO>

§

impl<S, F, STO> !Unpin for Task<S, F, STO>

§

impl<S, F, STO> !UnwindSafe for Task<S, F, STO>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.