use crate::import::*;
pub type ChanRes<T, I> = Result<T, ChanErr<I>>;
#[ derive(Eq) ]
pub struct ChanErr<I>
{
pub(crate) kind: ChanErrKind,
pub(crate) item: Option<I>,
}
unsafe impl<I: Send> Sync for ChanErr<I> {}
impl<I: Send> ChanErr<I>
{
pub fn item( &mut self ) -> Option<I>
{
self.item.take()
}
pub fn kind( &mut self ) -> ChanErrKind
{
self.kind
}
}
#[ derive( Copy, Clone, Debug, PartialEq, Eq ) ]
pub enum ChanErrKind
{
Closed,
}
impl<I> std::error::Error for ChanErr<I>
{
}
impl<I> fmt::Debug for ChanErr<I>
{
fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result
{
match self.kind
{
ChanErrKind::Closed => write!( f, "The channel Sender is already closed." ) ,
}
}
}
impl<I> fmt::Display for ChanErr<I>
{
fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result
{
write!( f, "{}", self )
}
}
impl<I> PartialEq for ChanErr<I>
{
fn eq( &self, other: &ChanErr<I> ) -> bool
{
self.kind == other.kind
}
}