pub trait SomeStaticExecutor: 'static + Debug {
type ExecutorNotifier: ExecutorNotified;
// Required methods
fn spawn_static<F, Notifier: ObserverNotified<F::Output>>(
&mut self,
task: Task<F, Notifier>,
) -> impl Observer<Value = F::Output>
where Self: Sized,
F: Future + 'static,
F::Output: 'static + Unpin;
fn spawn_static_async<F, Notifier: ObserverNotified<F::Output>>(
&mut self,
task: Task<F, Notifier>,
) -> impl Future<Output = impl Observer<Value = F::Output>>
where Self: Sized,
F: Future + 'static,
F::Output: 'static + Unpin;
fn spawn_static_objsafe(
&mut self,
task: ObjSafeStaticTask,
) -> BoxedStaticObserver;
fn spawn_static_objsafe_async<'s>(
&'s mut self,
task: ObjSafeStaticTask,
) -> BoxedStaticObserverFuture<'s>;
fn clone_box(&self) -> Box<DynStaticExecutor>;
fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>;
}Expand description
A trait for executors that can spawn static, non-Send tasks.
This trait is designed for executors that can handle futures with a 'static lifetime
but without the Send bound. This is useful for cases where you need static data
without the overhead of Send synchronization.
Unlike SomeExecutor which requires Send and SomeLocalExecutor which supports
arbitrary lifetimes, SomeStaticExecutor specifically targets the middle ground
of static lifetime without Send requirements.
§Use Cases
- Thread-local static data access
- Executors that work with static futures but don’t need Send
- Applications with static lifetimes but thread-local execution
- Bridge between local and global executor patterns
Required Associated Types§
Sourcetype ExecutorNotifier: ExecutorNotified
type ExecutorNotifier: ExecutorNotified
The notifier handle that can wake or signal work for this executor.
Required Methods§
Sourcefn spawn_static<F, Notifier: ObserverNotified<F::Output>>(
&mut self,
task: Task<F, Notifier>,
) -> impl Observer<Value = F::Output>
fn spawn_static<F, Notifier: ObserverNotified<F::Output>>( &mut self, task: Task<F, Notifier>, ) -> impl Observer<Value = F::Output>
Spawns a static, non-Send future onto the runtime.
§Parameters
task: The task to spawn containing a ’static future
§Note
The future must be 'static but does not need to be Send. This allows
for static data access without the synchronization overhead of Send.
§Implementation notes
For details on why F::Output is Unpin, see the comment on observer::TypedObserver.
Sourcefn spawn_static_async<F, Notifier: ObserverNotified<F::Output>>(
&mut self,
task: Task<F, Notifier>,
) -> impl Future<Output = impl Observer<Value = F::Output>>
fn spawn_static_async<F, Notifier: ObserverNotified<F::Output>>( &mut self, task: Task<F, Notifier>, ) -> impl Future<Output = impl Observer<Value = F::Output>>
Spawns a static, non-Send future onto the runtime.
Like Self::spawn_static, but some implementors may have a fast path for the async context.
§Implementation notes
For details on why F::Output is Unpin, see the comment on observer::TypedObserver.
Sourcefn spawn_static_objsafe(
&mut self,
task: ObjSafeStaticTask,
) -> BoxedStaticObserver
fn spawn_static_objsafe( &mut self, task: ObjSafeStaticTask, ) -> BoxedStaticObserver
Spawns a static, non-Send future onto the runtime.
§Note
This differs from Self::spawn_static in that we take a boxed future, since we can’t have generic fn. Implementations probably pin this with Box::into_pin.
Sourcefn spawn_static_objsafe_async<'s>(
&'s mut self,
task: ObjSafeStaticTask,
) -> BoxedStaticObserverFuture<'s>
fn spawn_static_objsafe_async<'s>( &'s mut self, task: ObjSafeStaticTask, ) -> BoxedStaticObserverFuture<'s>
Spawns a static, non-Send future onto the runtime.
§Note
This differs from Self::spawn_static in that we take a boxed future, since we can’t have generic fn. Implementations probably pin this with Box::into_pin.
Sourcefn clone_box(&self) -> Box<DynStaticExecutor>
fn clone_box(&self) -> Box<DynStaticExecutor>
Clones the executor.
The returned value will spawn tasks onto the same executor.
Sourcefn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
Produces an executor notifier.
Trait Implementations§
Source§impl<UnderlyingNotifier: ExecutorNotified> SomeStaticExecutor for Box<dyn SomeStaticExecutor<ExecutorNotifier = UnderlyingNotifier>>
Implementation of SomeStaticExecutor for boxed static executor trait objects.
impl<UnderlyingNotifier: ExecutorNotified> SomeStaticExecutor for Box<dyn SomeStaticExecutor<ExecutorNotifier = UnderlyingNotifier>>
Implementation of SomeStaticExecutor for boxed static executor trait objects.
This implementation enables Box<dyn SomeStaticExecutor> to act as a static executor,
supporting !Send futures through type erasure. This is particularly useful for
single-threaded or local executors.
§Differences from SomeExecutor
Unlike the SomeExecutor implementation, this works with futures that are not Send,
making it suitable for JavaScript/WASM environments or thread-local execution contexts.
§Examples
let mut executor: Box<dyn SomeStaticExecutor<ExecutorNotifier = Infallible>> = todo!();
// Can spawn !Send futures
let rc = Rc::new(42);
let task = Task::without_notifications(
"rc-task".to_string(),
Configuration::default(),
async move { *rc }
);Source§fn spawn_static<F, Notifier: ObserverNotified<F::Output>>(
&mut self,
task: Task<F, Notifier>,
) -> impl Observer<Value = F::Output>
fn spawn_static<F, Notifier: ObserverNotified<F::Output>>( &mut self, task: Task<F, Notifier>, ) -> impl Observer<Value = F::Output>
Spawns a static (potentially !Send) future onto the underlying executor.
This method supports futures that don’t implement Send, making it suitable
for single-threaded environments.
Source§async fn spawn_static_async<F, Notifier: ObserverNotified<F::Output>>(
&mut self,
task: Task<F, Notifier>,
) -> impl Observer<Value = F::Output>
async fn spawn_static_async<F, Notifier: ObserverNotified<F::Output>>( &mut self, task: Task<F, Notifier>, ) -> impl Observer<Value = F::Output>
Asynchronously spawns a static future onto the underlying executor.
The async version of spawn_static for executors that need async initialization.
Source§fn spawn_static_objsafe(
&mut self,
task: ObjSafeStaticTask,
) -> BoxedStaticObserver
fn spawn_static_objsafe( &mut self, task: ObjSafeStaticTask, ) -> BoxedStaticObserver
Spawns an already type-erased static task.
This is the object-safe method for static executors. User code typically doesn’t call this directly.
Source§fn spawn_static_objsafe_async<'s>(
&'s mut self,
task: ObjSafeStaticTask,
) -> BoxedStaticObserverFuture<'s>
fn spawn_static_objsafe_async<'s>( &'s mut self, task: ObjSafeStaticTask, ) -> BoxedStaticObserverFuture<'s>
Asynchronously spawns an already type-erased static task.
The async version of spawn_static_objsafe.
Source§fn clone_box(&self) -> Box<DynStaticExecutor>
fn clone_box(&self) -> Box<DynStaticExecutor>
Creates a boxed clone of the static executor.
Source§fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
Gets a notifier for executor-level events, if supported.
Source§type ExecutorNotifier = Box<dyn ExecutorNotified>
type ExecutorNotifier = Box<dyn ExecutorNotified>
Implementations on Foreign Types§
Source§impl SomeStaticExecutor for Infallible
impl SomeStaticExecutor for Infallible
type ExecutorNotifier = Infallible
fn spawn_static<F, Notifier: ObserverNotified<F::Output>>( &mut self, _task: Task<F, Notifier>, ) -> impl Observer<Value = F::Output>
fn spawn_static_async<F, Notifier: ObserverNotified<F::Output>>( &mut self, _task: Task<F, Notifier>, ) -> impl Future<Output = impl Observer<Value = F::Output>>
fn spawn_static_objsafe( &mut self, _task: ObjSafeStaticTask, ) -> BoxedStaticObserver
fn spawn_static_objsafe_async<'s>( &'s mut self, _task: ObjSafeStaticTask, ) -> BoxedStaticObserverFuture<'s>
fn clone_box(&self) -> Box<DynStaticExecutor>
fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
Source§impl<UnderlyingNotifier: ExecutorNotified> SomeStaticExecutor for Box<dyn SomeStaticExecutor<ExecutorNotifier = UnderlyingNotifier>>
Implementation of SomeStaticExecutor for boxed static executor trait objects.
impl<UnderlyingNotifier: ExecutorNotified> SomeStaticExecutor for Box<dyn SomeStaticExecutor<ExecutorNotifier = UnderlyingNotifier>>
Implementation of SomeStaticExecutor for boxed static executor trait objects.
This implementation enables Box<dyn SomeStaticExecutor> to act as a static executor,
supporting !Send futures through type erasure. This is particularly useful for
single-threaded or local executors.
§Differences from SomeExecutor
Unlike the SomeExecutor implementation, this works with futures that are not Send,
making it suitable for JavaScript/WASM environments or thread-local execution contexts.
§Examples
let mut executor: Box<dyn SomeStaticExecutor<ExecutorNotifier = Infallible>> = todo!();
// Can spawn !Send futures
let rc = Rc::new(42);
let task = Task::without_notifications(
"rc-task".to_string(),
Configuration::default(),
async move { *rc }
);Source§fn spawn_static<F, Notifier: ObserverNotified<F::Output>>(
&mut self,
task: Task<F, Notifier>,
) -> impl Observer<Value = F::Output>
fn spawn_static<F, Notifier: ObserverNotified<F::Output>>( &mut self, task: Task<F, Notifier>, ) -> impl Observer<Value = F::Output>
Spawns a static (potentially !Send) future onto the underlying executor.
This method supports futures that don’t implement Send, making it suitable
for single-threaded environments.
Source§async fn spawn_static_async<F, Notifier: ObserverNotified<F::Output>>(
&mut self,
task: Task<F, Notifier>,
) -> impl Observer<Value = F::Output>
async fn spawn_static_async<F, Notifier: ObserverNotified<F::Output>>( &mut self, task: Task<F, Notifier>, ) -> impl Observer<Value = F::Output>
Asynchronously spawns a static future onto the underlying executor.
The async version of spawn_static for executors that need async initialization.
Source§fn spawn_static_objsafe(
&mut self,
task: ObjSafeStaticTask,
) -> BoxedStaticObserver
fn spawn_static_objsafe( &mut self, task: ObjSafeStaticTask, ) -> BoxedStaticObserver
Spawns an already type-erased static task.
This is the object-safe method for static executors. User code typically doesn’t call this directly.
Source§fn spawn_static_objsafe_async<'s>(
&'s mut self,
task: ObjSafeStaticTask,
) -> BoxedStaticObserverFuture<'s>
fn spawn_static_objsafe_async<'s>( &'s mut self, task: ObjSafeStaticTask, ) -> BoxedStaticObserverFuture<'s>
Asynchronously spawns an already type-erased static task.
The async version of spawn_static_objsafe.
Source§fn clone_box(&self) -> Box<DynStaticExecutor>
fn clone_box(&self) -> Box<DynStaticExecutor>
Creates a boxed clone of the static executor.
Source§fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
Gets a notifier for executor-level events, if supported.