#![deny(missing_docs)]
use std::fmt;
pub mod buffer;
pub mod mpmc;
pub mod mpsc;
pub mod spmc;
pub mod spsc;
mod util;
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum PushError<T> {
Disconnected(T),
}
impl<T> fmt::Debug for PushError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Disconnected(_) => f.pad("Disconnected(_)"),
}
}
}
impl<T> fmt::Display for PushError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Disconnected(_) => "queue abandoned".fmt(f),
}
}
}
impl<T> std::error::Error for PushError<T> {}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum TryPushError<T> {
Full(T),
Disconnected(T),
}
impl<T> fmt::Debug for TryPushError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Full(_) => f.pad("Full(_)"),
Self::Disconnected(_) => f.pad("Disconnected(_)"),
}
}
}
impl<T> fmt::Display for TryPushError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Full(_) => "queue full".fmt(f),
Self::Disconnected(_) => "queue abandoned".fmt(f),
}
}
}
impl<T> std::error::Error for TryPushError<T> {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PopError {
Disconnected,
}
impl fmt::Display for PopError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Disconnected => "queue abandoned".fmt(f),
}
}
}
impl std::error::Error for PopError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TryPopError {
Empty,
Disconnected,
}
impl fmt::Display for TryPopError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Empty => "queue empty".fmt(f),
Self::Disconnected => "queue abandoned".fmt(f),
}
}
}
impl std::error::Error for TryPopError {}
pub trait Producer<T> {
fn push(&self, value: T) -> Result<(), PushError<T>>;
fn try_push(&self, value: T) -> Result<(), TryPushError<T>>;
}
pub trait Consumer<T> {
fn pop(&self) -> Result<T, PopError>;
fn try_pop(&self) -> Result<T, TryPopError>;
}