Skip to content

Commit 527a639

Browse files
authoredMar 15, 2022
feat: add into_inner and Error impl to Full (#43)
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
1 parent 463d542 commit 527a639

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed
 

‎src/lib.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ pub struct Ref<'slot, T> {
6464
new_state: usize,
6565
}
6666

67-
/// Error returned when sending a message failed because a channel is at capacity.
68-
#[derive(Eq, PartialEq)]
67+
/// Error indicating that a `push` operation failed because a queue was at
68+
/// capacity.
69+
///
70+
/// This is returned by the [`ThingBuf::push`] and [`ThingBuf::push_ref`] (and
71+
/// [`StaticThingBuf::push`]/[`StaticThingBuf::push_ref`]) methods.
72+
#[derive(PartialEq, Eq)]
6973
pub struct Full<T = ()>(T);
7074

7175
/// State variables for the atomic ring buffer algorithm.
@@ -524,6 +528,18 @@ impl<T> Slot<T> {
524528

525529
unsafe impl<T: Sync> Sync for Slot<T> {}
526530

531+
// === impl Full ===
532+
533+
impl<T> Full<T> {
534+
/// Unwraps the inner `T` value held by this error.
535+
///
536+
/// This method allows recovering the original message when sending to a
537+
/// channel has failed.
538+
pub fn into_inner(self) -> T {
539+
self.0
540+
}
541+
}
542+
527543
impl<T> fmt::Debug for Full<T> {
528544
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
529545
f.write_str("Full(..)")
@@ -532,6 +548,9 @@ impl<T> fmt::Debug for Full<T> {
532548

533549
impl<T> fmt::Display for Full<T> {
534550
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
535-
f.write_str("channel full")
551+
f.write_str("queue at capacity")
536552
}
537553
}
554+
555+
#[cfg(feature = "std")]
556+
impl<T> std::error::Error for Full<T> {}

‎src/mpsc/errors.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use core::fmt;
99
/// [`StaticSender::try_send`]: super::StaticSender::try_send
1010
/// [`StaticSender::try_send_ref`]: super::StaticSender::try_send_ref
1111
#[non_exhaustive]
12+
#[derive(PartialEq, Eq)]
1213
pub enum TrySendError<T = ()> {
1314
/// The data could not be sent on the channel because the channel is
1415
/// currently full and sending would require waiting for capacity.
@@ -29,6 +30,7 @@ pub enum TrySendError<T = ()> {
2930
/// [`StaticSender::send`]: super::StaticSender::send
3031
/// [`StaticSender::send_ref`]: super::StaticSender::send_ref
3132
/// [`Receiver`]: super::Receiver
33+
#[derive(PartialEq, Eq)]
3234
pub struct Closed<T = ()>(pub(crate) T);
3335

3436
// === impl Closed ===

0 commit comments

Comments
 (0)
Please sign in to comment.