From eeaf6c429a9535c7f64c3c8c86949a3761daffe7 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Tue, 23 Jul 2024 20:17:47 +0300 Subject: [PATCH] Add a fn to check if two senders or two receivers use the same underlying channel. --- src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 245a216..0374376 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -196,6 +196,7 @@ pub struct Sender { } impl Sender { + /// Attempts to send a message into the channel. /// /// If the channel is full or closed, this method returns an error. @@ -493,6 +494,11 @@ impl Sender { channel: self.channel.clone(), } } + + /// Returns whether the senders belong to the same channel. + pub fn same_channel(&self, other: &Sender) -> bool { + Arc::ptr_eq(&self.channel, &other.channel) + } } impl Drop for Sender { @@ -820,6 +826,11 @@ impl Receiver { channel: self.channel.clone(), } } + + /// Returns whether the receivers belong to the same channel. + pub fn same_channel(&self, other: &Receiver) -> bool { + Arc::ptr_eq(&self.channel, &other.channel) + } } impl fmt::Debug for Receiver {