From 886f971e94b5dd6b823d37869d6038cd26d81ba0 Mon Sep 17 00:00:00 2001
From: Eliza Weisman <eliza@buoyant.io>
Date: Tue, 15 Mar 2022 14:08:01 -0700
Subject: [PATCH 1/2] feat: add `into_inner` and `Error` impl to `Full`

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
---
 src/lib.rs | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs
index f226b11..51bc1b2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -63,8 +63,11 @@ pub struct Ref<'slot, T> {
     new_state: usize,
 }
 
-/// Error returned when sending a message failed because a channel is at capacity.
-#[derive(Eq, PartialEq)]
+/// Error indicating that a `push` operation failed because a queue was at
+/// capacity.
+///
+/// This is returned by the [`ThingBuf::push`] and [`ThingBuf::push_ref`] (and
+/// [`StaticThingBuf::push`]/[`StaticThingBuf::push_ref`]) methods.
 pub struct Full<T = ()>(T);
 
 /// State variables for the atomic ring buffer algorithm.
@@ -523,6 +526,18 @@ impl<T> Slot<T> {
 
 unsafe impl<T: Sync> Sync for Slot<T> {}
 
+// === impl Full ===
+
+impl<T> Full<T> {
+    /// Unwraps the inner `T` value held by this error.
+    ///
+    /// This method allows recovering the original message when sending to a
+    /// channel has failed.
+    pub fn into_inner(self) -> T {
+        self.0
+    }
+}
+
 impl<T> fmt::Debug for Full<T> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.write_str("Full(..)")
@@ -531,6 +546,9 @@ impl<T> fmt::Debug for Full<T> {
 
 impl<T> fmt::Display for Full<T> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        f.write_str("channel full")
+        f.write_str("queue at capacity")
     }
 }
+
+#[cfg(feature = "std")]
+impl<T> std::error::Error for Full<T> {}

From 421bb260b4968193ec8f6fd3e4b76fea58f68150 Mon Sep 17 00:00:00 2001
From: Eliza Weisman <eliza@buoyant.io>
Date: Tue, 15 Mar 2022 14:14:34 -0700
Subject: [PATCH 2/2] add PartialEq and Eq impls

---
 src/lib.rs         | 1 +
 src/mpsc/errors.rs | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/src/lib.rs b/src/lib.rs
index 51bc1b2..1906dc2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -68,6 +68,7 @@ pub struct Ref<'slot, T> {
 ///
 /// This is returned by the [`ThingBuf::push`] and [`ThingBuf::push_ref`] (and
 /// [`StaticThingBuf::push`]/[`StaticThingBuf::push_ref`]) methods.
+#[derive(PartialEq, Eq)]
 pub struct Full<T = ()>(T);
 
 /// State variables for the atomic ring buffer algorithm.
diff --git a/src/mpsc/errors.rs b/src/mpsc/errors.rs
index f019c15..e044c75 100644
--- a/src/mpsc/errors.rs
+++ b/src/mpsc/errors.rs
@@ -9,6 +9,7 @@ use core::fmt;
 /// [`StaticSender::try_send`]: super::StaticSender::try_send
 /// [`StaticSender::try_send_ref`]: super::StaticSender::try_send_ref
 #[non_exhaustive]
+#[derive(PartialEq, Eq)]
 pub enum TrySendError<T = ()> {
     /// The data could not be sent on the channel because the channel is
     /// currently full and sending would require waiting for capacity.
@@ -29,6 +30,7 @@ pub enum TrySendError<T = ()> {
 /// [`StaticSender::send`]: super::StaticSender::send
 /// [`StaticSender::send_ref`]: super::StaticSender::send_ref
 /// [`Receiver`]: super::Receiver
+#[derive(PartialEq, Eq)]
 pub struct Closed<T = ()>(pub(crate) T);
 
 // === impl Closed ===