Struct maitake::task::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> !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.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T> Instrument for T

§

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

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

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>,

§

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>,

§

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more