Skip to content

Conversation

@utkarshgupta137
Copy link
Contributor

@utkarshgupta137 utkarshgupta137 commented Apr 27, 2023

Follow up to #75.

Copy link
Owner

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, this looks good to me, except for some minor documentation issues! i'm going to make the suggested changes and then go ahead and merge this.

@hawkw hawkw enabled auto-merge (squash) April 28, 2023 16:47
Comment on lines 113 to 165
impl SendTimeoutError {
#[cfg(feature = "std")]
pub(crate) fn with_value<T>(self, value: T) -> SendTimeoutError<T> {
match self {
Self::Timeout(()) => SendTimeoutError::Timeout(value),
Self::Closed(()) => SendTimeoutError::Closed(value),
}
}
}

impl<T> SendTimeoutError<T> {
/// Returns `true` if this error was returned because the channel is still
/// full after the timeout has elapsed.
pub fn is_timeout(&self) -> bool {
matches!(self, Self::Timeout(_))
}

/// Returns `true` if this error was returned because the channel has closed
/// (e.g. the [`Receiver`] end has been dropped).
///
/// If this returns `true`, no future [`try_send`] or [`send`] operation on
/// this channel will succeed.
///
/// [`Receiver`]: super::Receiver
/// [`try_send`]: super::Sender::try_send
/// [`send`]: super::Sender::send
/// [`Receiver`]: super::Receiver
pub fn is_closed(&self) -> bool {
matches!(self, Self::Timeout(_))
}

/// 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 {
match self {
Self::Timeout(val) => val,
Self::Closed(val) => val,
}
}
}

impl<T> fmt::Debug for SendTimeoutError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Timeout(_) => "SendTimeoutError::Timeout(..)",
Self::Closed(_) => "SendTimeoutError::Closed(..)",
})
}
}

impl<T> fmt::Display for SendTimeoutError<T> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
impl SendTimeoutError {
#[cfg(feature = "std")]
pub(crate) fn with_value<T>(self, value: T) -> SendTimeoutError<T> {
match self {
Self::Timeout(()) => SendTimeoutError::Timeout(value),
Self::Closed(()) => SendTimeoutError::Closed(value),
}
}
}
impl<T> SendTimeoutError<T> {
/// Returns `true` if this error was returned because the channel is still
/// full after the timeout has elapsed.
pub fn is_timeout(&self) -> bool {
matches!(self, Self::Timeout(_))
}
/// Returns `true` if this error was returned because the channel has closed
/// (e.g. the [`Receiver`] end has been dropped).
///
/// If this returns `true`, no future [`try_send`] or [`send`] operation on
/// this channel will succeed.
///
/// [`Receiver`]: super::Receiver
/// [`try_send`]: super::Sender::try_send
/// [`send`]: super::Sender::send
/// [`Receiver`]: super::Receiver
pub fn is_closed(&self) -> bool {
matches!(self, Self::Timeout(_))
}
/// 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 {
match self {
Self::Timeout(val) => val,
Self::Closed(val) => val,
}
}
}
impl<T> fmt::Debug for SendTimeoutError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Timeout(_) => "SendTimeoutError::Timeout(..)",
Self::Closed(_) => "SendTimeoutError::Closed(..)",
})
}
}
impl<T> fmt::Display for SendTimeoutError<T> {
#[cfg(feature = "std")]
impl SendTimeoutError {
pub(crate) fn with_value<T>(self, value: T) -> SendTimeoutError<T> {
match self {
Self::Timeout(()) => SendTimeoutError::Timeout(value),
Self::Closed(()) => SendTimeoutError::Closed(value),
}
}
}
#[cfg(feature = "std")]
impl<T> SendTimeoutError<T> {
/// Returns `true` if this error was returned because the channel is still
/// full after the timeout has elapsed.
pub fn is_timeout(&self) -> bool {
matches!(self, Self::Timeout(_))
}
/// Returns `true` if this error was returned because the channel has closed
/// (e.g. the [`Receiver`] end has been dropped).
///
/// If this returns `true`, no future [`try_send`] or [`send`] operation on
/// this channel will succeed.
///
/// [`Receiver`]: super::Receiver
/// [`try_send`]: super::Sender::try_send
/// [`send`]: super::Sender::send
/// [`Receiver`]: super::Receiver
pub fn is_closed(&self) -> bool {
matches!(self, Self::Timeout(_))
}
/// 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 {
match self {
Self::Timeout(val) => val,
Self::Closed(val) => val,
}
}
}
#[cfg(feature = "std")]
impl<T> fmt::Debug for SendTimeoutError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Timeout(_) => "SendTimeoutError::Timeout(..)",
Self::Closed(_) => "SendTimeoutError::Closed(..)",
})
}
}
#[cfg(feature = "std")]
impl<T> fmt::Display for SendTimeoutError<T> {

@hawkw hawkw merged commit 979ed6e into hawkw:main Apr 28, 2023
@utkarshgupta137
Copy link
Contributor Author

@hawkw We're still waiting for a release with #75 & perhaps this change as well. You had tagged the 0.1.4 release on GitHub, but not published it to crates.io. Request you to do that when possible.

@hawkw
Copy link
Owner

hawkw commented May 1, 2023

@utkarshgupta137 whoops, sorry about that! I thought I had set up a workflow that publishes to crates.io on tags, but I must not have done that.

@hawkw
Copy link
Owner

hawkw commented May 1, 2023

Okay, I've published v0.1.4 with this change and the change from #75. Sorry for the delay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants