#![forbid(unsafe_code)]
use core::{fmt, fmt::Debug};
#[derive(PartialEq, Eq, Clone, Copy)]
pub struct SendError<T>(pub T);
impl<T> Debug for SendError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "SendError(..)")
}
}
impl<T> fmt::Display for SendError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt("send to a closed channel", f)
}
}
impl<T> SendError<T> {
#[inline]
pub fn into_inner(self) -> T {
self.0
}
}
impl<T> core::error::Error for SendError<T> {}
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum SendTimeoutError<T> {
Closed(T),
Timeout(T),
}
impl<T> Debug for SendTimeoutError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
SendTimeoutError::Closed(..) => write!(f, "Closed(..)"),
SendTimeoutError::Timeout(..) => write!(f, "Timeout(..)"),
}
}
}
impl<T> fmt::Display for SendTimeoutError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(
match *self {
SendTimeoutError::Closed(..) => "send to a closed channel",
SendTimeoutError::Timeout(..) => "send timeout",
},
f,
)
}
}
impl<T> SendTimeoutError<T> {
#[inline]
pub fn into_inner(self) -> T {
match self {
SendTimeoutError::Closed(value) => value,
SendTimeoutError::Timeout(value) => value,
}
}
}
impl<T> core::error::Error for SendTimeoutError<T> {}
#[derive(Debug, PartialEq, Eq)]
pub struct ReceiveError();
impl core::error::Error for ReceiveError {}
impl fmt::Display for ReceiveError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt("receive from a closed channel", f)
}
}
#[derive(Debug, PartialEq, Eq)]
pub enum ReceiveErrorTimeout {
Closed,
Timeout,
}
impl core::error::Error for ReceiveErrorTimeout {}
impl fmt::Display for ReceiveErrorTimeout {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(
match *self {
ReceiveErrorTimeout::Closed => "receive from a closed channel",
ReceiveErrorTimeout::Timeout => "receive timeout",
},
f,
)
}
}
#[derive(Debug, PartialEq, Eq)]
pub struct CloseError();
impl core::error::Error for CloseError {}
impl fmt::Display for CloseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt("channel is already closed", f)
}
}