Repository navigation
feat(spmc): add endpoint state queries, bounded reservation, and trait assertions - #450
Merged
Merged
Conversation
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]>
8 tasks done
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bring
spmcinto parity withmpscandmpmcacross endpoint state inspection, two-phase bounded capacity reservation, and compile-time auto-trait coverage in three focused commits:is_disconnectedandis_emptytospmcendpoints: Exposeis_disconnectedonspmc::BoundedSender,UnboundedSender,BoundedReceiver, andUnboundedReceiver, and exposeis_emptyonBoundedReceiverandUnboundedReceivermatching the liveness and buffered-value snapshot contracts ofmpscandmpmc.reserveandtry_reservetospmc::BoundedSender: ExposeBoundedSender::{reserve, try_reserve}returningspmc::Permit<'_, T>so the exclusive producer can wait for capacity before constructing a value. BecauseBoundedSenderrequires&mut self, holdingPermitretains the exclusive sender borrow and keeps the reserved slot available without extra reservation-counter bookkeeping or lock acquisitions when dropping an unused permit.spmcendpoints andPermitintraits_test: Consolidatespmcendpoint,Permit, error, and async-future auto-trait checks intotraits_test, verifyingSend,Sync,Unpin,UnwindSafe, andRefUnwindSafeacrossmpsc,mpmc, andspmcendpoints andPermits forSendpayloads (i32,Cell<u8>,&mut i32, andPhantomPinned).Part of #445