embassy-executor

Crates

git

Versions

wasm

Flavors

embassy_executor::raw

Struct TaskStorage

Source
#[repr(C)]
pub struct TaskStorage<F: Future + 'static> { /* private fields */ }
Expand description

Raw storage in which a task can be spawned.

This struct holds the necessary memory to spawn one task whose future is F. At a given time, the TaskStorage may be in spawned or not-spawned state. You may spawn it with TaskStorage::spawn(), which will fail if it is already spawned.

A TaskStorage must live forever, it may not be deallocated even after the task has finished running. Hence the relevant methods require &'static self. It may be reused, however.

Internally, the embassy_executor::task macro allocates an array of TaskStorages in a static. The most common reason to use the raw Task is to have control of where the memory for the task is allocated: on the stack, or on the heap with e.g. Box::leak, etc.

Implementations§

Source§

impl<F: Future + 'static> TaskStorage<F>

Source

pub const fn new() -> Self

Create a new TaskStorage, in not-spawned state.

Source

pub fn spawn( &'static self, future: impl FnOnce() -> F, ) -> SpawnToken<impl Sized>

Try to spawn the task.

The future closure constructs the future. It’s only called if spawning is actually possible. It is a closure instead of a simple future: F param to ensure the future is constructed in-place, avoiding a temporary copy in the stack thanks to NRVO optimizations.

This function will fail if the task is already spawned and has not finished running. In this case, the error is delayed: a “poisoned” SpawnToken is returned, which will cause Spawner::spawn() to return the error.

Once the task has finished running, you may spawn it again. It is allowed to spawn it on a different executor.

Auto Trait Implementations§

§

impl<F> !Freeze for TaskStorage<F>

§

impl<F> !RefUnwindSafe for TaskStorage<F>

§

impl<F> Send for TaskStorage<F>
where F: Send,

§

impl<F> Sync for TaskStorage<F>

§

impl<F> Unpin for TaskStorage<F>
where F: Unpin,

§

impl<F> !UnwindSafe for TaskStorage<F>

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