Skip to content

Commit b7bcaa5

Browse files
committed
Auto merge of #143741 - connortsui20:oneshot, r=joboet
`oneshot` Channel Tracking Issue: #143674 This PR adds an experimental `oneshot` module. Before talking about the API itself, I would prefer to get some of these questions below out of the way first. And as discussed in the [ACP](rust-lang/libs-team#610) it would be # Unresolved Questions - [x] ~~Why exactly is it okay for `Sender` to be `Sync`? Or basically, how do we boil down the discussion in #111087 into a comment for the `unsafe impl<T: Send> Sync for Sender<T> {}`?~~ - [x] ~~Why is `mpsc::Receiver` `!Sync` but `mpmc::Receiver` is `Sync`? Should `oneshot::Receiver` be `Sync` or not?~~ - [ ] Should this PR try to add an `is_ready` method as proposed in the tracking issue? If so, then the surface of this PR would likely need to increase to add a `pub(crate) fn is_disconnected` method to `mpmc` (might even be a good idea to add that to all 3 channel flavors). - [ ] In a similar vein to the previous question, should the first internal implementation simply be a wrapper around `mpmc`, or should it be a wrapper around the internal crossbeam implementation? - [ ] Should the `Sender` and `Receiver` operations be methods or associated methods? So `sender.send(msg)` or `Sender::send(sender, msg)`? The method syntax is more consistent with the rest of the ecosystem (namely `tokio`)
2 parents 9e8a0c5 + b481ecd commit b7bcaa5

6 files changed

Lines changed: 819 additions & 4 deletions

File tree

library/std/src/sync/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ pub use alloc_crate::sync::{Arc, Weak};
184184
#[unstable(feature = "mpmc_channel", issue = "126840")]
185185
pub mod mpmc;
186186
pub mod mpsc;
187+
#[unstable(feature = "oneshot_channel", issue = "143674")]
188+
pub mod oneshot;
187189

188190
pub(crate) mod once; // `pub(crate)` for the `sys::sync::once` implementations and `LazyLock`.
189191

library/std/src/sync/mpmc/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ impl<T> Clone for Sender<T> {
654654
#[unstable(feature = "mpmc_channel", issue = "126840")]
655655
impl<T> fmt::Debug for Sender<T> {
656656
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
657-
f.pad("Sender { .. }")
657+
f.debug_struct("Sender").finish_non_exhaustive()
658658
}
659659
}
660660

@@ -1380,7 +1380,7 @@ impl<T> Clone for Receiver<T> {
13801380
#[unstable(feature = "mpmc_channel", issue = "126840")]
13811381
impl<T> fmt::Debug for Receiver<T> {
13821382
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1383-
f.pad("Receiver { .. }")
1383+
f.debug_struct("Receiver").finish_non_exhaustive()
13841384
}
13851385
}
13861386

library/std/src/sync/mpsc.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,8 +1114,10 @@ impl<T> error::Error for SendError<T> {}
11141114
impl<T> fmt::Debug for TrySendError<T> {
11151115
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11161116
match *self {
1117-
TrySendError::Full(..) => "Full(..)".fmt(f),
1118-
TrySendError::Disconnected(..) => "Disconnected(..)".fmt(f),
1117+
TrySendError::Full(..) => f.debug_tuple("TrySendError::Full").finish_non_exhaustive(),
1118+
TrySendError::Disconnected(..) => {
1119+
f.debug_tuple("TrySendError::Disconnected").finish_non_exhaustive()
1120+
}
11191121
}
11201122
}
11211123
}

0 commit comments

Comments
 (0)