Add the spawner trait#83
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces an executor-agnostic Spawner trait and wires it into the client’s per-socket I/O loop submission points, moving the crate closer to bare-metal portability while keeping the existing std + tokio behavior via a TokioSpawner adapter.
Changes:
- Added
transport::Spawneras a minimal task-submission abstraction for driving per-socket I/O loops concurrently with the client run loop. - Implemented
TokioSpawner(wrapper overtokio::spawn) and plumbed a user-providedSpawnerthroughClient/InnerandSocketManagerbind paths. - Updated docs/examples and added tests to verify spawns are routed through the injected
Spawner.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/transport.rs | Adds the new Spawner trait and extensive rationale/usage docs. |
| src/tokio_transport.rs | Introduces TokioSpawner and implements transport::Spawner using tokio::spawn. |
| src/lib.rs | Re-exports Spawner and TokioSpawner; updates crate docs on bare-metal limitations. |
| src/client/socket_manager.rs | Replaces direct tokio::spawn with a caller-supplied Spawner for socket loops. |
| src/client/mod.rs | Adds Client::new_with_spawner_and_loopback constructor and a routing test. |
| src/client/inner.rs | Stores the injected spawner in Inner and routes discovery/unicast binds through it; adds tests. |
| examples/discovery_client/src/main.rs | Minor formatting update to match constructor style. |
| examples/client_server/src/main.rs | Minor formatting update to match constructor style. |
| examples/bare_metal/src/main.rs | Updates caveats and demonstrates compiling against the new Spawner trait. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Round-2 Copilot feedback on PR #79: - src/tokio_transport.rs:129 recv_from: `tokio::net::UdpSocket:: recv_from` silently truncates when the caller's buf is smaller than the datagram — it does not expose a truncation flag. The `ReceivedDatagram::truncated` field therefore always reports `false` on the Tokio backend. Reliable truncation detection would require a libc + unsafe `recvmsg`/MSG_TRUNC path, deferred to the phase 10+ bare-metal refactor. Added a precise in-line comment naming the platform limitation so callers don't mis-trust the field. - src/tokio_transport.rs:213 map_io_error: the post-mapping logging previously unconditionally used `warn!` for every I/O error, which turned common steady-state conditions (TimedOut, Interrupted, ConnectionRefused during transient outages) into warning noise that can drown out actionable signal. Triaged by kind: common-path kinds drop to `debug!`; unexpected / misconfiguration-indicating kinds (PermissionDenied, AddrInUse, NetworkUnreachable, fallback Other) stay at `warn!`. Comment explains the rationale. - src/transport.rs module docs: the `crate::tokio_transport::*` intra-doc links broke under default-feature rustdoc builds (the `tokio_transport` module is gated to `client`/`server`). Same resolution as the PR #83 intra-doc fixes in ee305e0: render the paths as code literals and add an inline note that the module requires those features. Keeps the information, drops the link. No new behavior paths introduced — logging changes + docs only. Existing tokio_transport test suite (6/6) still passes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Follow-up to 3f93900 — the intra-doc fix for the `crate::tokio_transport::*` links in transport.rs didn't get saved before the commit closed. Same resolution as the PR #83 fix in ee305e0: render feature-gated paths as code literals rather than intra-doc links, add inline note explaining why. Verified with `RUSTDOCFLAGS=-D rustdoc::broken-intra-doc-links cargo doc --no-deps` — default-feature docs now clean. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Round-2 Copilot feedback on PR #79: - src/tokio_transport.rs:129 recv_from: `tokio::net::UdpSocket:: recv_from` silently truncates when the caller's buf is smaller than the datagram — it does not expose a truncation flag. The `ReceivedDatagram::truncated` field therefore always reports `false` on the Tokio backend. Reliable truncation detection would require a libc + unsafe `recvmsg`/MSG_TRUNC path, deferred to the phase 10+ bare-metal refactor. Added a precise in-line comment naming the platform limitation so callers don't mis-trust the field. - src/tokio_transport.rs:213 map_io_error: the post-mapping logging previously unconditionally used `warn!` for every I/O error, which turned common steady-state conditions (TimedOut, Interrupted, ConnectionRefused during transient outages) into warning noise that can drown out actionable signal. Triaged by kind: common-path kinds drop to `debug!`; unexpected / misconfiguration-indicating kinds (PermissionDenied, AddrInUse, NetworkUnreachable, fallback Other) stay at `warn!`. Comment explains the rationale. - src/transport.rs module docs: the `crate::tokio_transport::*` intra-doc links broke under default-feature rustdoc builds (the `tokio_transport` module is gated to `client`/`server`). Same resolution as the PR #83 intra-doc fixes in ee305e0: render the paths as code literals and add an inline note that the module requires those features. Keeps the information, drops the link. No new behavior paths introduced — logging changes + docs only. Existing tokio_transport test suite (6/6) still passes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Follow-up to 3f93900 — the intra-doc fix for the `crate::tokio_transport::*` links in transport.rs didn't get saved before the commit closed. Same resolution as the PR #83 fix in ee305e0: render feature-gated paths as code literals rather than intra-doc links, add inline note explaining why. Verified with `RUSTDOCFLAGS=-D rustdoc::broken-intra-doc-links cargo doc --no-deps` — default-feature docs now clean. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1e92f43 to
e4ab414
Compare
Final state of #83, squashed from 6 commits to keep the rebase onto the rewritten #82 tractable. Original commits, oldest first: - cfbd17a Added a Spawner trait in transport.rs. TokioSpawner is the default std impl. Client::new_with_spawner_and_loopback accepts a caller-supplied spawner so the bare-metal port can drive socket loops without tokio. New unit tests and bare_metal example now demonstrates usage with a MockSpawner. - 9122afd New bind tests; corrected documentation throughout to reflect the concrete next steps toward bare-metal support. - ee305e0 phase 9: fix intra-doc links that break default-feature rustdoc builds. Three sites that referenced feature-gated items via intra-doc links: tokio_transport's `[Spawner]` -> `[crate::transport::Spawner]`; transport.rs link to `[crate::tokio_transport::TokioSpawner]` -> code literal with feature-gate note; same pattern at transport.rs:478 for `[crate::client::Client]`. Also lib.rs module table: intra-doc links for feature-gated `[client]` / `[server]` modules -> plain code literals. - d618081 round-2: fix intra-doc link + correct channel-capacity docs. Replace the intra-doc link to Client::new_with_spawner_and_loopback in tokio_transport.rs with a plain code literal (breaks default-feature rustdoc in feature="server"-without-feature="client"). Correct socket_manager module doc: per-socket mpsc channels are 16/16 for discovery sockets, 4/4 for unicast (verified against mpsc::channel call sites). - d2c44e0 chore(clippy): address new warnings in phase9 PR (13 fixes). doc_markdown: backtick `no_alloc`, `no_std`, `bare_metal` identifiers in new docs. double_must_use on Client::new_with_spawner_and_loopback: replace bare #[must_use] with a message about the run-loop future. dead_code on SocketManager::{bind, bind_discovery_seeded}: gate under #[cfg(test)] since the Spawner refactor removes non-test callers. - 721223c round-3: address Copilot review on socket_manager doc links + test JoinHandle. socket_manager: render TokioTransport / TokioSpawner refs as code literals (same rustdoc-feature-gating pattern as elsewhere in the PR) so default-feature doc builds no longer see broken intra-doc links. client::tests: bind the JoinHandle from tokio::spawn(future) to `_` in the CountingSpawner test so the #[must_use] lint does not fire. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
721223c to
e87c128
Compare
Added a spawner trait to inch closer to bare metal support
This PR is part of a chain. See Prev: #82; See Next: ???