Embassy
embassy-executor

Crates

git

Versions

cortex-m

Flavors

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

§

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.