From b6d906d7a2ee23b0fc27c5a24331f9bbfa2fb0fd Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Mon, 29 Jul 2024 10:29:57 +0300 Subject: [PATCH] Add example usage for fn same_channel in Sender and Receiver --- src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 685ac3e..3bdc944 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -495,6 +495,19 @@ impl Sender { } /// Returns whether the senders belong to the same channel. + /// + /// # Examples + /// + /// ``` + /// # futures_lite::future::block_on(async { + /// use async_channel::unbounded; + /// + /// let (s, r) = unbounded::<()>(); + /// let s2 = s.clone(); + /// + /// assert!(s.same_channel(&s2)); + /// # }); + /// ``` pub fn same_channel(&self, other: &Sender) -> bool { Arc::ptr_eq(&self.channel, &other.channel) } @@ -827,6 +840,19 @@ impl Receiver { } /// Returns whether the receivers belong to the same channel. + /// + /// # Examples + /// + /// ``` + /// # futures_lite::future::block_on(async { + /// use async_channel::unbounded; + /// + /// let (s, r) = unbounded::<()>(); + /// let r2 = r.clone(); + /// + /// assert!(r.same_channel(&r2)); + /// # }); + /// ``` pub fn same_channel(&self, other: &Receiver) -> bool { Arc::ptr_eq(&self.channel, &other.channel) }