1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
pub mod connection; pub mod dataframe; pub mod handshake; pub mod message; pub mod server; pub use self::connection::*; pub use self::dataframe::*; pub use self::handshake::*; pub use self::message::*; pub use self::server::*; pub use async_channel; pub use async_net; pub use async_std; pub use async_trait; pub use futures; use async_channel::{Receiver, Sender}; pub type Channel<T> = (Sender<T>, Receiver<T>); pub type AsyncResult<T> = Result<T, std::io::Error>; pub type WsGonzaleResult<T> = Result<T, WsGonzaleError>; #[derive(Debug, PartialEq)] pub enum WsGonzaleError { InvalidPayload, ConnectionClosed, Unknown, } impl From<std::io::Error> for WsGonzaleError { fn from(error: std::io::Error) -> Self { match error.kind() { std::io::ErrorKind::ConnectionAborted | std::io::ErrorKind::Interrupted | std::io::ErrorKind::AddrInUse | std::io::ErrorKind::AddrNotAvailable | std::io::ErrorKind::ConnectionRefused | std::io::ErrorKind::ConnectionReset | std::io::ErrorKind::NotConnected => WsGonzaleError::ConnectionClosed, _ => WsGonzaleError::Unknown, } } } impl From<WsGonzaleError> for std::io::Error { fn from(error: WsGonzaleError) -> Self { let error_kind = match error { WsGonzaleError::ConnectionClosed => std::io::ErrorKind::ConnectionAborted, WsGonzaleError::InvalidPayload => std::io::ErrorKind::InvalidData, _ => std::io::ErrorKind::Other, }; std::io::Error::from(error_kind) } }