Skip to content

Commit 2606400

Browse files
committed
better debug messages and comments
Signed-off-by: Connor Tsui <[email protected]>
1 parent 4e0bddc commit 2606400

File tree

1 file changed

+61
-65
lines changed

1 file changed

+61
-65
lines changed

library/std/src/sync/oneshot.rs

Lines changed: 61 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use crate::{error, fmt};
1212
/// # Examples
1313
///
1414
/// ```
15-
/// # #![feature(oneshot_channel)]
16-
/// # use std::sync::oneshot;
17-
/// # use std::thread;
18-
/// #
15+
/// #![feature(oneshot_channel)]
16+
/// use std::sync::oneshot;
17+
/// use std::thread;
18+
///
1919
/// let (sender, receiver) = oneshot::channel();
2020
///
2121
/// // Spawn off an expensive computation.
@@ -50,10 +50,10 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
5050
/// # Examples
5151
///
5252
/// ```
53-
/// # #![feature(oneshot_channel)]
54-
/// # use std::sync::oneshot;
55-
/// # use std::thread;
56-
/// #
53+
/// #![feature(oneshot_channel)]
54+
/// use std::sync::oneshot;
55+
/// use std::thread;
56+
///
5757
/// let (sender, receiver) = oneshot::channel();
5858
///
5959
/// thread::spawn(move || {
@@ -66,11 +66,11 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
6666
/// `Sender` cannot be sent between threads if it is sending non-`Send` types.
6767
///
6868
/// ```compile_fail
69-
/// # #![feature(oneshot_channel)]
70-
/// # use std::sync::oneshot;
71-
/// # use std::thread;
72-
/// # use std::ptr;
73-
/// #
69+
/// #![feature(oneshot_channel)]
70+
/// use std::sync::oneshot;
71+
/// use std::thread;
72+
/// use std::ptr;
73+
///
7474
/// let (sender, receiver) = oneshot::channel();
7575
///
7676
/// struct NotSend(*mut ());
@@ -86,11 +86,9 @@ pub struct Sender<T> {
8686
inner: mpmc::Sender<T>,
8787
}
8888

89-
/// # Safety
90-
///
91-
/// Since the only methods in which synchronization must occur take full ownership of the
92-
/// [`Sender`], it is perfectly safe to share a `&Sender` between threads (as it is effectively
93-
/// useless without ownership).
89+
// SAFETY: Since the only methods in which synchronization must occur take full ownership of the
90+
// [`Sender`], it is perfectly safe to share a `&Sender` between threads (as it is effectively
91+
// useless without ownership).
9492
#[unstable(feature = "oneshot_channel", issue = "143674")]
9593
unsafe impl<T> Sync for Sender<T> {}
9694

@@ -103,10 +101,10 @@ impl<T> Sender<T> {
103101
/// # Examples
104102
///
105103
/// ```
106-
/// # #![feature(oneshot_channel)]
107-
/// # use std::sync::oneshot;
108-
/// # use std::thread;
109-
/// #
104+
/// #![feature(oneshot_channel)]
105+
/// use std::sync::oneshot;
106+
/// use std::thread;
107+
///
110108
/// let (tx, rx) = oneshot::channel();
111109
///
112110
/// thread::spawn(move || {
@@ -126,7 +124,7 @@ impl<T> Sender<T> {
126124
#[unstable(feature = "oneshot_channel", issue = "143674")]
127125
impl<T> fmt::Debug for Sender<T> {
128126
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
129-
f.pad("Sender { .. }")
127+
f.debug_struct("Sender").finish_non_exhaustive()
130128
}
131129
}
132130

@@ -139,11 +137,11 @@ impl<T> fmt::Debug for Sender<T> {
139137
/// # Examples
140138
///
141139
/// ```
142-
/// # #![feature(oneshot_channel)]
143-
/// # use std::sync::oneshot;
144-
/// # use std::thread;
145-
/// # use std::time::Duration;
146-
/// #
140+
/// #![feature(oneshot_channel)]
141+
/// use std::sync::oneshot;
142+
/// use std::thread;
143+
/// use std::time::Duration;
144+
///
147145
/// let (sender, receiver) = oneshot::channel();
148146
///
149147
/// thread::spawn(move || {
@@ -178,11 +176,9 @@ pub struct Receiver<T> {
178176
inner: mpmc::Receiver<T>,
179177
}
180178

181-
/// # Safety
182-
///
183-
/// Since the only methods in which synchronization must occur take full ownership of the
184-
/// [`Receiver`], it is perfectly safe to share a `&Receiver` between threads (as it is unable to
185-
/// receive any values without ownership).
179+
// SAFETY: Since the only methods in which synchronization must occur take full ownership of the
180+
// [`Receiver`], it is perfectly safe to share a `&Receiver` between threads (as it is unable to
181+
// receive any values without ownership).
186182
#[unstable(feature = "oneshot_channel", issue = "143674")]
187183
unsafe impl<T> Sync for Receiver<T> {}
188184

@@ -194,11 +190,11 @@ impl<T> Receiver<T> {
194190
/// # Examples
195191
///
196192
/// ```
197-
/// # #![feature(oneshot_channel)]
198-
/// # use std::sync::oneshot;
199-
/// # use std::thread;
200-
/// # use std::time::Duration;
201-
/// #
193+
/// #![feature(oneshot_channel)]
194+
/// use std::sync::oneshot;
195+
/// use std::thread;
196+
/// use std::time::Duration;
197+
///
202198
/// let (tx, rx) = oneshot::channel();
203199
///
204200
/// thread::spawn(move || {
@@ -221,11 +217,11 @@ impl<T> Receiver<T> {
221217
/// # Examples
222218
///
223219
/// ```
224-
/// # #![feature(oneshot_channel)]
225-
/// # use std::sync::oneshot;
226-
/// # use std::thread;
227-
/// # use std::time::Duration;
228-
/// #
220+
/// #![feature(oneshot_channel)]
221+
/// use std::sync::oneshot;
222+
/// use std::thread;
223+
/// use std::time::Duration;
224+
///
229225
/// let (sender, mut receiver) = oneshot::channel();
230226
///
231227
/// thread::spawn(move || {
@@ -264,11 +260,11 @@ impl<T> Receiver<T> {
264260
/// # Examples
265261
///
266262
/// ```
267-
/// # #![feature(oneshot_channel)]
268-
/// # use std::sync::oneshot;
269-
/// # use std::thread;
270-
/// # use std::time::Duration;
271-
/// #
263+
/// #![feature(oneshot_channel)]
264+
/// use std::sync::oneshot;
265+
/// use std::thread;
266+
/// use std::time::Duration;
267+
///
272268
/// let (sender, receiver) = oneshot::channel();
273269
///
274270
/// thread::spawn(move || {
@@ -297,11 +293,11 @@ impl<T> Receiver<T> {
297293
/// # Examples
298294
///
299295
/// ```
300-
/// # #![feature(oneshot_channel)]
301-
/// # use std::sync::oneshot;
302-
/// # use std::thread;
303-
/// # use std::time::{Duration, Instant};
304-
/// #
296+
/// #![feature(oneshot_channel)]
297+
/// use std::sync::oneshot;
298+
/// use std::thread;
299+
/// use std::time::{Duration, Instant};
300+
///
305301
/// let (sender, receiver) = oneshot::channel();
306302
///
307303
/// thread::spawn(move || {
@@ -328,7 +324,7 @@ impl<T> Receiver<T> {
328324
#[unstable(feature = "oneshot_channel", issue = "143674")]
329325
impl<T> fmt::Debug for Receiver<T> {
330326
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
331-
f.pad("Receiver { .. }")
327+
f.debug_struct("Receiver").finish_non_exhaustive()
332328
}
333329
}
334330

@@ -360,11 +356,11 @@ pub enum TryRecvError<T> {
360356
/// Usage of this error is similar to [`TryRecvError`].
361357
///
362358
/// ```
363-
/// # #![feature(oneshot_channel)]
364-
/// # use std::sync::oneshot::{self, RecvTimeoutError};
365-
/// # use std::thread;
366-
/// # use std::time::Duration;
367-
/// #
359+
/// #![feature(oneshot_channel)]
360+
/// use std::sync::oneshot::{self, RecvTimeoutError};
361+
/// use std::thread;
362+
/// use std::time::Duration;
363+
///
368364
/// let (sender, receiver) = oneshot::channel();
369365
///
370366
/// thread::spawn(move || {
@@ -399,16 +395,16 @@ pub enum RecvTimeoutError<T> {
399395
#[unstable(feature = "oneshot_channel", issue = "143674")]
400396
impl<T> fmt::Debug for TryRecvError<T> {
401397
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
402-
"TryRecvError(..)".fmt(f)
398+
"oneshot::TryRecvError(..)".fmt(f)
403399
}
404400
}
405401

406402
#[unstable(feature = "oneshot_channel", issue = "143674")]
407403
impl<T> fmt::Display for TryRecvError<T> {
408404
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
409405
match *self {
410-
TryRecvError::Empty(..) => "receiving on an empty channel".fmt(f),
411-
TryRecvError::Disconnected => "receiving on a closed channel".fmt(f),
406+
TryRecvError::Empty(..) => "receiving on an empty oneshot channel".fmt(f),
407+
TryRecvError::Disconnected => "receiving on a closed oneshot channel".fmt(f),
412408
}
413409
}
414410
}
@@ -433,16 +429,16 @@ impl<T> From<RecvError> for TryRecvError<T> {
433429
#[unstable(feature = "oneshot_channel", issue = "143674")]
434430
impl<T> fmt::Debug for RecvTimeoutError<T> {
435431
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
436-
"RecvTimeoutError(..)".fmt(f)
432+
"oneshot::RecvTimeoutError(..)".fmt(f)
437433
}
438434
}
439435

440436
#[unstable(feature = "oneshot_channel", issue = "143674")]
441437
impl<T> fmt::Display for RecvTimeoutError<T> {
442438
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
443439
match *self {
444-
RecvTimeoutError::Timeout(..) => "timed out waiting on channel".fmt(f),
445-
RecvTimeoutError::Disconnected => "receiving on a closed channel".fmt(f),
440+
RecvTimeoutError::Timeout(..) => "timed out waiting on oneshot channel".fmt(f),
441+
RecvTimeoutError::Disconnected => "receiving on a closed oneshot channel".fmt(f),
446442
}
447443
}
448444
}

0 commit comments

Comments
 (0)