diff --git a/README.md b/README.md index d31024d..5ff7af5 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ * Minimal and Efficient : minimal codebase to provide efficient, memory-safe WebSocket handling. -* Multi Environment : `tokio`, `smol`, `glommio` are supported as async runtime ( by feature flags `rt_{name}` ). +* Multi-Environment : `tokio`, `smol`, `glommio` are supported as async runtime ( by feature flags `rt_{name}` ). ## Note @@ -33,10 +33,11 @@ mews = { version = "0.2", features = ["rt_tokio"] } tokio = { version = "1", features = ["rt"] } # ... ``` -*( with pseudo Request & Response )* -```rust +**( with pseudo Request & Response )** +```rust,ignore /* server */ +use tokio::net::TcpStream; use mews::{WebSocketContext, Connection, Message}; async fn handle_websocket( @@ -48,7 +49,7 @@ async fn handle_websocket( ); let (sign, ws) = ctx.on_upgrade( - |mut conn: Connection| async move { + |mut conn: Connection| async move { while let Ok(Some(Message::Text(text))) = conn.recv().await { conn.send(text).await .expect("failed to send message"); @@ -67,9 +68,11 @@ async fn handle_websocket( ws.manage(tcp); } ``` -```rust +```rust,ignore /* client */ +use tokio::net::TcpStream; + async fn start_websocket( mut tcp: TcpStream ) { @@ -80,7 +83,7 @@ async fn start_websocket( ); let (sign, ws) = ctx.on_upgrade( - |mut conn: Connection| async move { + |mut conn: Connection| async move { conn.send("Hello!").await.expect("failed to send message"); while let Ok(Some(Message::Text(text))) = conn.recv().await { println!("got: `{text}`") diff --git a/src/connection.rs b/src/connection.rs index 0101eb8..82ef8a4 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -5,7 +5,7 @@ use std::{sync::Arc, io::Error}; pub trait UnderlyingConnection: AsyncRead + AsyncWrite + Unpin + 'static {} impl UnderlyingConnection for T {} -pub struct Connection { +pub struct Connection { __closed__: Arc>, conn: Arc>, @@ -343,14 +343,6 @@ pub mod split { ::split(self) } } - #[cfg(feature="rt_nio")] - impl<'split> Splitable<'split> for nio::net::TcpStream { - type ReadHalf = nio::net::tcp::ReadHalf <'split>; - type WriteHalf = nio::net::tcp::WriteHalf<'split>; - fn split(&'split mut self) -> (Self::ReadHalf, Self::WriteHalf) { - ::split(self) - } - } #[cfg(feature="rt_glommio")] impl<'split, T: AsyncRead + AsyncWrite + Unpin + 'split> Splitable<'split> for T { type ReadHalf = futures_util::io::ReadHalf <&'split mut T>; @@ -371,7 +363,7 @@ pub mod split { } }; - pub struct ReadHalf>::ReadHalf> { + pub struct ReadHalf { __closed__: Arc>, conn: C, config: Config, @@ -389,7 +381,7 @@ pub mod split { } } - pub struct WriteHalf>::WriteHalf> { + pub struct WriteHalf { __closed__: Arc>, conn: C, config: Config, diff --git a/src/lib.rs b/src/lib.rs index 64e9f40..b55a599 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,6 @@ compile_error! {"More than one runtime feature flags can't be activated"} mod runtime { #[cfg(feature="rt_tokio")] pub use { - tokio::net::TcpStream, tokio::io::AsyncReadExt as AsyncRead, tokio::io::AsyncWriteExt as AsyncWrite, tokio::sync::RwLock, @@ -45,7 +44,6 @@ mod runtime { #[cfg(feature="rt_smol")] pub use { - smol::net::TcpStream, smol::io::AsyncReadExt as AsyncRead, smol::io::AsyncWriteExt as AsyncWrite, smol::lock::RwLock, @@ -57,7 +55,6 @@ mod runtime { #[cfg(feature="rt_glommio")] pub use { - glommio::net::TcpStream, futures_util::AsyncReadExt as AsyncRead, futures_util::AsyncWriteExt as AsyncWrite, glommio::sync::RwLock, diff --git a/src/websocket.rs b/src/websocket.rs index 5fd246b..406c4db 100644 --- a/src/websocket.rs +++ b/src/websocket.rs @@ -1,4 +1,3 @@ -use crate::runtime; use crate::message::{CloseFrame, CloseCode}; use crate::connection::{UnderlyingConnection, Connection}; @@ -47,7 +46,7 @@ pub type Handler = Box| async move { /// while let Ok(Some(Message::Text(text))) = conn.recv().await { /// conn.send(text).await /// .expect("failed to send message"); @@ -130,7 +129,7 @@ const _: () = { /// tcp: TcpStream /// ) -> Response { /// let (sign, ws) = ctx.on_upgrade( -/// |mut conn: Connection| async move { +/// |mut conn: Connection| async move { /// while let Ok(Some(Message::Text(text))) = conn.recv().await { /// conn.send(text).await /// .expect("failed to send message"); @@ -145,7 +144,7 @@ const _: () = { /// } /// ``` #[must_use = "`WebSocket` does nothing unless `.manage()` or `.manage_with_timeout()` is called"] -pub struct WebSocket { +pub struct WebSocket { config: Config, handler: Handler, } @@ -185,7 +184,7 @@ impl WebSocket { const _: () = { impl PartialEq for WebSocket where - dyn FnOnce(Connection) -> std::pin::Pin + Send + 'static)>> + Send + Sync + dyn FnOnce(Connection) -> std::pin::Pin + Send + 'static>> + Send + Sync : PartialEq { fn eq(&self, other: &Self) -> bool {