dambi 0.1.1

Single-threaded (!Send + !Sync) primitives
Documentation
mod local;

use std::fmt;

#[derive(Debug)]
pub struct SendError<T>(pub T);

impl<T> fmt::Display for SendError<T> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str("channel receiver dropped before send")
    }
}

impl<T: fmt::Debug> std::error::Error for SendError<T> {}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ClosedError;

impl fmt::Display for ClosedError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str("channel is closed")
    }
}

impl std::error::Error for ClosedError {}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TryRecvError {
    Empty,
    Closed,
}

impl fmt::Display for TryRecvError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Empty => f.write_str("channel is empty"),
            Self::Closed => f.write_str("channel is closed"),
        }
    }
}

impl std::error::Error for TryRecvError {}

pub use local::{Receiver, Send, Sender, channel, unbounded};