Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 51f2c04

Browse files
committed
Manually implement Debug for Sender/SyncSender/Receiver too
1 parent 94fbcaf commit 51f2c04

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/main_context_channel.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use get_thread_id;
66
use glib_sys;
77
use std::cell::RefCell;
88
use std::collections::VecDeque;
9+
use std::fmt;
910
use std::mem;
1011
use std::ptr;
1112
use std::sync::mpsc;
@@ -17,7 +18,6 @@ use Priority;
1718
use Source;
1819
use SourceId;
1920

20-
#[derive(Debug)]
2121
enum ChannelSourceState {
2222
NotAttached,
2323
Attached(*mut glib_sys::GSource),
@@ -27,7 +27,6 @@ enum ChannelSourceState {
2727
unsafe impl Send for ChannelSourceState {}
2828
unsafe impl Sync for ChannelSourceState {}
2929

30-
#[derive(Debug)]
3130
struct ChannelInner<T> {
3231
queue: VecDeque<T>,
3332
source: ChannelSourceState,
@@ -71,13 +70,11 @@ impl<T> ChannelInner<T> {
7170
}
7271
}
7372

74-
#[derive(Debug)]
7573
struct ChannelBound {
7674
bound: usize,
7775
cond: Condvar,
7876
}
7977

80-
#[derive(Debug)]
8178
struct Channel<T>(Arc<(Mutex<ChannelInner<T>>, Option<ChannelBound>)>);
8279

8380
impl<T> Clone for Channel<T> {
@@ -321,9 +318,14 @@ unsafe extern "C" fn finalize<T, F: FnMut(T) -> Continue + 'static>(
321318
/// See [`MainContext::channel()`] for how to create such a `Sender`.
322319
///
323320
/// [`MainContext::channel()`]: struct.MainContext.html#method.channel
324-
#[derive(Debug)]
325321
pub struct Sender<T>(Option<Channel<T>>);
326322

323+
impl<T> fmt::Debug for Sender<T> {
324+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
325+
f.debug_struct("Sender").finish()
326+
}
327+
}
328+
327329
impl<T> Clone for Sender<T> {
328330
fn clone(&self) -> Sender<T> {
329331
Sender(self.0.clone())
@@ -369,9 +371,14 @@ impl<T> Drop for Sender<T> {
369371
/// See [`MainContext::sync_channel()`] for how to create such a `SyncSender`.
370372
///
371373
/// [`MainContext::sync_channel()`]: struct.MainContext.html#method.sync_channel
372-
#[derive(Debug)]
373374
pub struct SyncSender<T>(Option<Channel<T>>);
374375

376+
impl<T> fmt::Debug for SyncSender<T> {
377+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
378+
f.debug_struct("SyncSender").finish()
379+
}
380+
}
381+
375382
impl<T> Clone for SyncSender<T> {
376383
fn clone(&self) -> SyncSender<T> {
377384
SyncSender(self.0.clone())
@@ -423,9 +430,14 @@ impl<T> Drop for SyncSender<T> {
423430
///
424431
/// [`MainContext::channel()`]: struct.MainContext.html#method.channel
425432
/// [`MainContext::sync_channel()`]: struct.MainContext.html#method.sync_channel
426-
#[derive(Debug)]
427433
pub struct Receiver<T>(Option<Channel<T>>, Priority);
428434

435+
impl<T> fmt::Debug for Receiver<T> {
436+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
437+
f.debug_struct("Receiver").finish()
438+
}
439+
}
440+
429441
// It's safe to send the Receiver to other threads for attaching it as
430442
// long as the items to be sent can also be sent between threads.
431443
unsafe impl<T: Send> Send for Receiver<T> {}

0 commit comments

Comments
 (0)