Skip to content

feat(spmc): add endpoint state queries, bounded reservation, and trait assertions - #450

Merged
tisonkun merged 4 commits into
mainfrom
feat/spmc-parity-and-reserve
Nov 22, 2026
Merged

tisonkun merged 4 commits into
mainfrom
feat/spmc-parity-and-reserve

Conversation

@tisonkun

Copy link
Copy Markdown
Member

Summary

Bring spmc into parity with mpsc and mpmc across endpoint state inspection, two-phase bounded capacity reservation, and compile-time auto-trait coverage in three focused commits:

  1. Add is_disconnected and is_empty to spmc endpoints: Expose is_disconnected on spmc::BoundedSender, UnboundedSender, BoundedReceiver, and UnboundedReceiver, and expose is_empty on BoundedReceiver and UnboundedReceiver matching the liveness and buffered-value snapshot contracts of mpsc and mpmc.
  2. Add reserve and try_reserve to spmc::BoundedSender: Expose BoundedSender::{reserve, try_reserve} returning spmc::Permit<'_, T> so the exclusive producer can wait for capacity before constructing a value. Because BoundedSender requires &mut self, holding Permit retains the exclusive sender borrow and keeps the reserved slot available without extra reservation-counter bookkeeping or lock acquisitions when dropping an unused permit.
  3. Cover spmc endpoints and Permit in traits_test: Consolidate spmc endpoint, Permit, error, and async-future auto-trait checks into traits_test, verifying Send, Sync, Unpin, UnwindSafe, and RefUnwindSafe across mpsc, mpmc, and spmc endpoints and Permits for Send payloads (i32, Cell<u8>, &mut i32, and PhantomPinned).

Part of #445

tisonkun and others added 3 commits November 22, 2026 17:57
Add `is_disconnected` to `spmc::BoundedSender`, `UnboundedSender`, `BoundedReceiver`, and `UnboundedReceiver`, and add `is_empty` to `BoundedReceiver` and `UnboundedReceiver`, matching the endpoint liveness and buffered-value snapshot contracts of `mpsc` and `mpmc`.
Expose `BoundedSender::{reserve, try_reserve}` returning `spmc::Permit<'_, T>` so the single producer can wait for queue capacity before constructing a value. Because `BoundedSender` requires `&mut self`, holding `Permit` retains the exclusive sender borrow and keeps the reserved slot available without extra reservation-counter bookkeeping or lock acquisitions on unused-permit drop.
Consolidate `spmc` endpoint, `Permit`, error, and async-future auto-trait checks into `traits_test`, verifying `Send`, `Sync`, `Unpin`, `UnwindSafe`, and `RefUnwindSafe` across `mpsc`, `mpmc`, and `spmc` endpoints and `Permit`s for `Send` payloads including `Cell<u8>`, `&mut i32`, and `PhantomPinned`.

Co-authored-by: Yijun Zhao <[email protected]>
Remove the `compile_fail` blocks from `spmc`'s public module documentation that only restated ordinary Rust `!Clone` and `&mut self` borrow-checker rules already guaranteed by the method signatures and summarized in the overview prose.
@tisonkun
tisonkun merged commit 13b13e4 into main Nov 22, 2026
9 checks passed
@tisonkun
tisonkun deleted the feat/spmc-parity-and-reserve branch November 22, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant