#![deny(unsafe_op_in_unsafe_fn)]
#![warn(missing_docs, missing_debug_implementations)]
use core::fmt;
pub mod mpsc;
pub mod spsc;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SendError<T>(pub T);
impl<T> SendError<T> {
pub fn into_inner(self) -> T {
self.0
}
}
impl<T> fmt::Display for SendError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "channel disconnected")
}
}
impl<T: fmt::Debug> std::error::Error for SendError<T> {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RecvError;
impl fmt::Display for RecvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "channel disconnected")
}
}
impl std::error::Error for RecvError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TrySendError<T> {
Full(T),
Disconnected(T),
}
impl<T> TrySendError<T> {
pub fn into_inner(self) -> T {
match self {
TrySendError::Full(v) | TrySendError::Disconnected(v) => v,
}
}
pub fn is_full(&self) -> bool {
matches!(self, TrySendError::Full(_))
}
pub fn is_disconnected(&self) -> bool {
matches!(self, TrySendError::Disconnected(_))
}
}
impl<T> fmt::Display for TrySendError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TrySendError::Full(_) => write!(f, "channel full"),
TrySendError::Disconnected(_) => write!(f, "channel disconnected"),
}
}
}
impl<T: fmt::Debug> std::error::Error for TrySendError<T> {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TryRecvError {
Empty,
Disconnected,
}
impl TryRecvError {
pub fn is_empty(&self) -> bool {
matches!(self, TryRecvError::Empty)
}
pub fn is_disconnected(&self) -> bool {
matches!(self, TryRecvError::Disconnected)
}
}
impl fmt::Display for TryRecvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TryRecvError::Empty => write!(f, "channel empty"),
TryRecvError::Disconnected => write!(f, "channel disconnected"),
}
}
}
impl std::error::Error for TryRecvError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RecvTimeoutError {
Timeout,
Disconnected,
}
impl RecvTimeoutError {
pub fn is_timeout(&self) -> bool {
matches!(self, RecvTimeoutError::Timeout)
}
pub fn is_disconnected(&self) -> bool {
matches!(self, RecvTimeoutError::Disconnected)
}
}
impl fmt::Display for RecvTimeoutError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RecvTimeoutError::Timeout => write!(f, "timed out"),
RecvTimeoutError::Disconnected => write!(f, "channel disconnected"),
}
}
}
impl std::error::Error for RecvTimeoutError {}