Skip to content

Commit

Permalink
Add a fn to check if two senders or two receivers use the same underl…
Browse files Browse the repository at this point in the history
…ying channel.
  • Loading branch information
rklaehn authored and notgull committed Jul 29, 2024
1 parent 1acd52b commit 681541a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ impl<T> Sender<T> {
channel: self.channel.clone(),
}
}

/// Returns whether the senders belong to the same channel.
pub fn same_channel(&self, other: &Sender<T>) -> bool {
Arc::ptr_eq(&self.channel, &other.channel)
}
}

impl<T> Drop for Sender<T> {
Expand Down Expand Up @@ -820,6 +825,11 @@ impl<T> Receiver<T> {
channel: self.channel.clone(),
}
}

/// Returns whether the receivers belong to the same channel.
pub fn same_channel(&self, other: &Receiver<T>) -> bool {
Arc::ptr_eq(&self.channel, &other.channel)
}
}

impl<T> fmt::Debug for Receiver<T> {
Expand Down

0 comments on commit 681541a

Please sign in to comment.