diff --git a/src/lib.rs b/src/lib.rs index 7a23f78..80fcac1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,8 +64,12 @@ 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. +#[derive(PartialEq, Eq)] pub struct Full(T); /// State variables for the atomic ring buffer algorithm. @@ -524,6 +528,18 @@ impl Slot { unsafe impl Sync for Slot {} +// === impl Full === + +impl Full { + /// 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 fmt::Debug for Full { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("Full(..)") @@ -532,6 +548,9 @@ impl fmt::Debug for Full { impl fmt::Display for Full { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str("channel full") + f.write_str("queue at capacity") } } + +#[cfg(feature = "std")] +impl std::error::Error for Full {} 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 { /// 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 { /// [`StaticSender::send`]: super::StaticSender::send /// [`StaticSender::send_ref`]: super::StaticSender::send_ref /// [`Receiver`]: super::Receiver +#[derive(PartialEq, Eq)] pub struct Closed(pub(crate) T); // === impl Closed ===