mod send_error;
mod try_recv_error;
use std::future::Future;
pub use send_error::SendError;
pub use try_recv_error::TryRecvError;
use crate::OptionalSend;
use crate::OptionalSync;
pub trait Mpsc: Sized + OptionalSend {
type Sender<T: OptionalSend>: MpscSender<Self, T>;
type Receiver<T: OptionalSend>: MpscReceiver<T>;
type WeakSender<T: OptionalSend>: MpscWeakSender<Self, T>;
#[track_caller]
fn channel<T: OptionalSend>(buffer: usize) -> (Self::Sender<T>, Self::Receiver<T>);
}
pub trait MpscSender<MU, T>: OptionalSend + OptionalSync + Clone
where
MU: Mpsc,
T: OptionalSend,
{
#[track_caller]
fn send(&self, msg: T) -> impl Future<Output = Result<(), SendError<T>>> + OptionalSend;
#[track_caller]
fn downgrade(&self) -> MU::WeakSender<T>;
}
pub trait MpscReceiver<T>: OptionalSend + OptionalSync {
#[track_caller]
fn recv(&mut self) -> impl Future<Output = Option<T>> + OptionalSend;
#[track_caller]
fn try_recv(&mut self) -> Result<T, TryRecvError>;
}
pub trait MpscWeakSender<MU, T>: OptionalSend + OptionalSync + Clone
where
MU: Mpsc,
T: OptionalSend,
{
#[track_caller]
fn upgrade(&self) -> Option<MU::Sender<T>>;
}