Crate executor_core

Crate executor_core 

Source
Expand description

§executor-core

A flexible task executor abstraction layer for Rust async runtimes.

This crate provides unified traits and type-erased wrappers for different async executors, allowing you to write code that’s agnostic to the underlying executor implementation.

§Overview

The crate is built around two main traits:

  • Executor: For spawning Send + 'static futures
  • LocalExecutor: For spawning 'static futures (not necessarily Send)

Both traits produce tasks that implement the Task trait, providing:

§Features

  • Zero-cost Executor Abstraction: Unified Executor and LocalExecutor traits using Generic Associated Types (GAT) to prevent unnecessary heap allocation and dynamic dispatch
  • Type Erasure: AnyExecutor and AnyLocalExecutor for runtime flexibility
  • Task Management: Panic-aware Task::result and background execution with Task::detach
  • No-std Compatible: Core functionality works in no-std environments
  • Panic Safety: Proper panic handling and propagation

§Lifetime Constraints

The current API requires 'static lifetimes for both futures and their outputs. This constraint comes from the underlying async runtimes and ensures memory safety when tasks may outlive their spawning scope. While this limits flexibility, it matches the constraints of most async runtime implementations in Rust.

Modules§

async_executorasync-executor
Integration with the async-executor crate.
async_taskasync-task
Integration with the async-task crate.
mailbox
Mailbox-based message passing for safe cross-thread communication.
tokiotokio
Integration with the Tokio async runtime.

Structs§

AnyExecutor
A type-erased Executor that can hold any executor implementation.
AnyExecutorTask
Task type returned by AnyExecutor.
AnyLocalExecutor
A type-erased LocalExecutor that can hold any local executor implementation.
AnyLocalExecutorTask
Task type returned by AnyLocalExecutor.
DefaultExecutorstd
A default executor that uses the global and local executors.
ResultFuture
Future returned by Task::result().

Traits§

Executor
A trait for spawning Send + 'static futures.
LocalExecutor
A trait for spawning 'static futures that may not be Send.
Task
A trait representing a spawned task that can be awaited or queried for results.

Functions§

init_global_executorstd
Initialize the global executor for spawning Send futures.
init_local_executorstd
Initialize the thread-local executor for spawning non-Send futures.
spawnstd
Spawn a Send future on the global executor.
spawn_localstd
Spawn a future on the thread-local executor.
try_init_global_executorstd
Try to initialize the global executor for spawning Send futures.
try_init_local_executorstd
Try to initialize the thread-local executor for spawning non-Send futures.