Executor

Trait Executor 

Source
pub trait Executor: Send + Sync {
    type Task<T: Send + 'static>: Task<T> + Send;

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

A trait for spawning Send + 'static futures.

This trait is implemented by runtime-agnostic executors that can spawn futures across thread boundaries. The spawned futures must be Send and 'static.

The 'static lifetime requirements come from the underlying async runtimes (like Tokio) which need to ensure memory safety when tasks are moved across threads and may outlive their spawning scope.

See AnyExecutor for a type-erased executor.

Required Associated Types§

Source

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

The task type returned by spawn.

The T: Send + 'static constraint ensures the task output can be safely sent across thread boundaries and doesn’t contain any borrowed data.

Required Methods§

Source

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

Spawn a future that will run to completion.

The future must be Send + 'static to ensure it can be moved across threads. 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: Executor> Executor for &E

Source§

type Task<T: Send + 'static> = <E as Executor>::Task<T>

Source§

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

Source§

impl<E: Executor> Executor for &mut E

Source§

type Task<T: Send + 'static> = <E as Executor>::Task<T>

Source§

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

Source§

impl<E: Executor> Executor for Box<E>

Source§

type Task<T: Send + 'static> = <E as Executor>::Task<T>

Source§

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

Source§

impl<E: Executor> Executor for Arc<E>

Source§

type Task<T: Send + 'static> = <E as Executor>::Task<T>

Source§

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

Implementors§

Source§

impl Executor for Executor<'static>

Available on crate feature async-executor only.
Source§

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

Source§

impl Executor for AnyExecutor

Source§

type Task<T: Send + 'static> = AnyExecutorTask<T>

Source§

impl Executor for DefaultExecutor

Source§

type Task<T: Send + 'static> = AnyExecutorTask<T>

Source§

impl Executor for Runtime

Available on crate feature tokio only.
Source§

type Task<T: Send + 'static> = TokioTask<T>

Source§

impl Executor for TokioExecutor

Available on crate feature tokio only.
Source§

type Task<T: Send + 'static> = TokioTask<T>

Source§

impl Executor for WebExecutor

Available on crate feature web only.
Source§

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