use core::fmt;
pub enum TrySendError<T> {
Full(T),
Closed(T),
}
impl<T> TrySendError<T> {
pub fn into_inner(self) -> T {
match self {
Self::Full(item) | Self::Closed(item) => item,
}
}
pub const fn is_full(&self) -> bool {
matches!(self, Self::Full(_))
}
pub const fn is_closed(&self) -> bool {
matches!(self, Self::Closed(_))
}
}
impl<T> fmt::Debug for TrySendError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Full(_) => "Full(..)",
Self::Closed(_) => "Closed(..)",
})
}
}
impl<T> fmt::Display for TrySendError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Full(_) => "sending on a full channel",
Self::Closed(_) => "sending on a closed channel",
})
}
}
impl<T> core::error::Error for TrySendError<T> {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TryRecvError {
Empty,
Disconnected,
}
impl TryRecvError {
pub const fn as_str(&self) -> &'static str {
match self {
Self::Empty => "receiving on an empty channel",
Self::Disconnected => "receiving on an empty and disconnected channel",
}
}
pub const fn is_empty(&self) -> bool {
matches!(self, Self::Empty)
}
pub const fn is_disconnected(&self) -> bool {
matches!(self, Self::Disconnected)
}
}
impl fmt::Display for TryRecvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl core::error::Error for TryRecvError {}
pub struct SendError<T>(T);
impl<T> SendError<T> {
pub(super) fn new(item: T) -> Self {
Self(item)
}
pub fn into_inner(self) -> T {
self.0
}
}
impl<T> fmt::Debug for SendError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("SendError(..)")
}
}
impl<T> fmt::Display for SendError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("sending on a closed channel")
}
}
impl<T> core::error::Error for SendError<T> {}