//! Provides a fundamental executor primitive appropriate for the target platform1//! and feature set selected.2//! By default, the `async_executor` feature will be enabled, which will rely on3//! [`async-executor`] for the underlying implementation. This requires `std`,4//! so is not suitable for `no_std` contexts. Instead, you must use `edge_executor`,5//! which relies on the alternate [`edge-executor`] backend.6//!7//! [`async-executor`]: https://crates.io/crates/async-executor8//! [`edge-executor`]: https://crates.io/crates/edge-executor910use core::{11fmt,12panic::{RefUnwindSafe, UnwindSafe},13};14use derive_more::{Deref, DerefMut};1516crate::cfg::async_executor! {17if {18type ExecutorInner<'a> = async_executor::Executor<'a>;19type LocalExecutorInner<'a> = async_executor::LocalExecutor<'a>;20} else {21type ExecutorInner<'a> = crate::edge_executor::Executor<'a, 64>;22type LocalExecutorInner<'a> = crate::edge_executor::LocalExecutor<'a, 64>;23}24}2526crate::cfg::multi_threaded! {27pub use async_task::FallibleTask;28}2930/// Wrapper around a multi-threading-aware async executor.31/// Spawning will generally require tasks to be `Send` and `Sync` to allow multiple32/// threads to send/receive/advance tasks.33///34/// If you require an executor _without_ the `Send` and `Sync` requirements, consider35/// using [`LocalExecutor`] instead.36#[derive(Deref, DerefMut, Default)]37pub struct Executor<'a>(ExecutorInner<'a>);3839/// Wrapper around a single-threaded async executor.40/// Spawning wont generally require tasks to be `Send` and `Sync`, at the cost of41/// this executor itself not being `Send` or `Sync`. This makes it unsuitable for42/// global statics.43///44/// If need to store an executor in a global static, or send across threads,45/// consider using [`Executor`] instead.46#[derive(Deref, DerefMut, Default)]47pub struct LocalExecutor<'a>(LocalExecutorInner<'a>);4849impl Executor<'_> {50/// Construct a new [`Executor`]51#[expect(clippy::allow_attributes, reason = "This lint may not always trigger.")]52#[allow(dead_code, reason = "not all feature flags require this function")]53pub const fn new() -> Self {54Self(ExecutorInner::new())55}56}5758impl LocalExecutor<'_> {59/// Construct a new [`LocalExecutor`]60#[expect(clippy::allow_attributes, reason = "This lint may not always trigger.")]61#[allow(dead_code, reason = "not all feature flags require this function")]62pub const fn new() -> Self {63Self(LocalExecutorInner::new())64}65}6667impl UnwindSafe for Executor<'_> {}6869impl RefUnwindSafe for Executor<'_> {}7071impl UnwindSafe for LocalExecutor<'_> {}7273impl RefUnwindSafe for LocalExecutor<'_> {}7475impl fmt::Debug for Executor<'_> {76fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {77f.debug_struct("Executor").finish()78}79}8081impl fmt::Debug for LocalExecutor<'_> {82fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {83f.debug_struct("LocalExecutor").finish()84}85}868788