pub trait LocalSpawner {
// Required method
fn spawn_local(&self, future: impl Future<Output = ()> + 'static);
}Expand description
Executor-agnostic task-spawning primitive.
simple-someip’s per-socket I/O loops need to run concurrently with
the client’s main event loop — otherwise SocketManager::send’s
internal oneshot wait deadlocks (the send future parks the main
loop, which is the only thing that would drive the socket loop to
produce its response). The Spawner trait lets std+tokio callers
pass a one-line TokioSpawner and bare-metal callers wrap their own
executor’s task-spawning primitive.
§Design rationale
The transport-trait design deliberately avoided wrapping spawn to
prevent “reinventing embassy” and trait-object dispatch in the hot
path. However, without a spawn abstraction, Inner::bind_* has to
call tokio::spawn directly — making the whole crate tokio-only.
The revised rule: spawn DOES need a trait, but we avoid the
concerns by (1) keeping the trait generic (monomorphized, no
dyn Spawner) and (2) scoping it narrowly — just spawn, not
select/sleep which have other solutions.
§Usage
On std + tokio, use crate::tokio_transport::TokioSpawner
(available when the client or server feature is enabled) —
a zero-size unit struct whose spawn is a thin wrapper around
tokio::spawn. The path is rendered as a code literal rather
than an intra-doc link because the target module is feature-gated
and would break default-feature rustdoc builds. On embedded:
struct EmbassySpawner(embassy_executor::Spawner);
impl simple_someip::Spawner for EmbassySpawner {
fn spawn(&self, fut: impl core::future::Future<Output = ()> + Send + 'static) {
// embassy's Spawner has its own task-registration model;
// the adapter layer depends on how the user defined their tasks
todo!("call self.0.spawn(...)");
}
}Local-executor counterpart to Spawner.
Where Spawner::spawn requires its future to be Send + 'static
(matching multi-threaded executors like tokio), LocalSpawner::spawn_local
drops the Send bound and is the trait that single-threaded
executors — embassy with task-arena = 0, tokio’s LocalSet, async-std
LocalExecutor, etc. — implement directly.
The two traits are independent: an executor MAY implement both
(current_thread tokio with LocalSet), only Spawner
(multi-threaded tokio default), or only LocalSpawner
(single-task embassy).
Use crate::client::Client::new_with_deps_local (under client) to
construct a Client whose run-loop and per-socket loops are submitted
through a
LocalSpawner (and whose TransportFactory::Socket is therefore
allowed to be !Send).
Required Methods§
Sourcefn spawn_local(&self, future: impl Future<Output = ()> + 'static)
fn spawn_local(&self, future: impl Future<Output = ()> + 'static)
Submit future to the local executor. Must not block; must
arrange for the future to be polled to completion on some
single-threaded task.
The future is not required to be Send — it may capture
Rc, RefCell, raw *mut pointers, etc.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".