Skip to content

Commit eeaf6c4

Browse files
committed
Add a fn to check if two senders or two receivers use the same underlying channel.
1 parent 1acd52b commit eeaf6c4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ pub struct Sender<T> {
196196
}
197197

198198
impl<T> Sender<T> {
199+
199200
/// Attempts to send a message into the channel.
200201
///
201202
/// If the channel is full or closed, this method returns an error.
@@ -493,6 +494,11 @@ impl<T> Sender<T> {
493494
channel: self.channel.clone(),
494495
}
495496
}
497+
498+
/// Returns whether the senders belong to the same channel.
499+
pub fn same_channel(&self, other: &Sender<T>) -> bool {
500+
Arc::ptr_eq(&self.channel, &other.channel)
501+
}
496502
}
497503

498504
impl<T> Drop for Sender<T> {
@@ -820,6 +826,11 @@ impl<T> Receiver<T> {
820826
channel: self.channel.clone(),
821827
}
822828
}
829+
830+
/// Returns whether the receivers belong to the same channel.
831+
pub fn same_channel(&self, other: &Receiver<T>) -> bool {
832+
Arc::ptr_eq(&self.channel, &other.channel)
833+
}
823834
}
824835

825836
impl<T> fmt::Debug for Receiver<T> {

0 commit comments

Comments
 (0)