use crate::{ import::* };
#[ derive( Debug ) ]
pub struct WsErr
{
inner: FailContext<WsErrKind>,
}
#[ derive( Clone, PartialEq, Eq, Debug, Fail ) ]
pub enum WsErrKind
{
#[ fail( display = "The WebSocket handshake failed" ) ]
WsHandshake,
#[ fail( display = "A tcp connection error happened" ) ]
TcpConnection,
#[ fail( display = "Invalid input to conversion to WsReadyState: {}", _0 ) ]
InvalidReadyState( u16 ),
}
impl Fail for WsErr
{
fn cause( &self ) -> Option< &dyn Fail >
{
self.inner.cause()
}
fn backtrace( &self ) -> Option< &Backtrace >
{
self.inner.backtrace()
}
}
impl fmt::Display for WsErr
{
fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result
{
fmt::Display::fmt( &self.inner, f )
}
}
impl WsErr
{
pub fn kind( &self ) -> &WsErrKind
{
self.inner.get_context()
}
}
impl From<WsErrKind> for WsErr
{
fn from( kind: WsErrKind ) -> WsErr
{
WsErr { inner: FailContext::new( kind ) }
}
}
impl From< FailContext<WsErrKind> > for WsErr
{
fn from( inner: FailContext<WsErrKind> ) -> WsErr
{
WsErr { inner }
}
}