use crate::{ import::* };
#[ derive( Debug, Error ) ]
#[ non_exhaustive ]
#[ allow( variant_size_differences ) ]
pub enum WsErr
{
#[ error( "A tungstenite error happened: {source}" )]
Tungstenite
{
source: tungstenite::Error
},
#[ error( "An io error happened: {source}" )]
Io
{
source: io::Error
},
#[ error( "The remote committed a websocket protocol violation." )]
Protocol,
#[ error( "The remote sent a Text message. Only Binary messages are accepted." )]
ReceivedText,
#[ error( "The connection is already closed." )]
Closed,
}
impl From< TungErr > for WsErr
{
fn from( inner: TungErr ) -> WsErr
{
match inner
{
TungErr::Protocol(_) => WsErr::Protocol ,
source => WsErr::Tungstenite{ source } ,
}
}
}
impl From< io::Error > for WsErr
{
fn from( source: io::Error ) -> WsErr
{
WsErr::Io { source }
}
}
impl From< pharos::Error > for WsErr
{
fn from( source: pharos::Error ) -> WsErr
{
match source.kind()
{
pharos::ErrorKind::Closed => WsErr::Closed,
_ => unreachable!() ,
}
}
}