LocalExecutor

Trait LocalExecutor 

Source
pub trait LocalExecutor {
    type Task<T: 'static>: Task<T>;

    // Required method
    fn spawn_local<Fut>(&self, fut: Fut) -> Self::Task<Fut::Output>
       where Fut: Future + 'static;
}
Expand description

A trait for spawning 'static futures that may not be Send.

This trait is for executors that can spawn futures that don’t need to be Send, typically single-threaded executors or local task spawners.

The 'static lifetime requirements come from the underlying async runtimes which need to ensure memory safety when tasks may outlive their spawning scope, even in single-threaded contexts.

See AnyLocalExecutor for a type-erased local executor.

Required Associated Types§

Source

type Task<T: 'static>: Task<T>

The task type returned by spawn.

The T: 'static constraint ensures the task output doesn’t contain any borrowed data that could become invalid.

Required Methods§

Source

fn spawn_local<Fut>(&self, fut: Fut) -> Self::Task<Fut::Output>
where Fut: Future + 'static,

Spawn a future that will run to completion on the local executor.

The future must be 'static but does not need to be Send. Returns a Task that can be awaited to get the result.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<E: LocalExecutor> LocalExecutor for &E

Source§

type Task<T: 'static> = <E as LocalExecutor>::Task<T>

Source§

fn spawn_local<Fut>(&self, fut: Fut) -> Self::Task<Fut::Output>
where Fut: Future + 'static,

Source§

impl<E: LocalExecutor> LocalExecutor for &mut E

Source§

type Task<T: 'static> = <E as LocalExecutor>::Task<T>

Source§

fn spawn_local<Fut>(&self, fut: Fut) -> Self::Task<Fut::Output>
where Fut: Future + 'static,

Source§

impl<E: LocalExecutor> LocalExecutor for Box<E>

Source§

type Task<T: 'static> = <E as LocalExecutor>::Task<T>

Source§

fn spawn_local<Fut>(&self, fut: Fut) -> Self::Task<Fut::Output>
where Fut: Future + 'static,

Source§

impl<E: LocalExecutor> LocalExecutor for Rc<E>

Source§

type Task<T: 'static> = <E as LocalExecutor>::Task<T>

Source§

fn spawn_local<Fut>(&self, fut: Fut) -> Self::Task<Fut::Output>
where Fut: Future + 'static,

Source§

impl<E: LocalExecutor> LocalExecutor for Arc<E>

Source§

type Task<T: 'static> = <E as LocalExecutor>::Task<T>

Source§

fn spawn_local<Fut>(&self, fut: Fut) -> Self::Task<Fut::Output>
where Fut: Future + 'static,

Implementors§

Source§

impl LocalExecutor for LocalExecutor<'static>

Available on crate feature async-executor only.
Source§

type Task<T: 'static> = AsyncTask<T>

Source§

impl LocalExecutor for AnyLocalExecutor

Source§

type Task<T: 'static> = AnyLocalExecutorTask<T>

Source§

impl LocalExecutor for DefaultExecutor

Source§

type Task<T: 'static> = AnyLocalExecutorTask<T>

Source§

impl LocalExecutor for LocalSet

Available on crate feature tokio only.
Source§

type Task<T: 'static> = TokioLocalTask<T>

Source§

impl LocalExecutor for TokioExecutor

Available on crate feature tokio only.
Source§

type Task<T: 'static> = TokioLocalTask<T>

Source§

impl LocalExecutor for WebExecutor

Available on crate feature web only.
Source§

type Task<T: 'static> = WebTask<T>