From f6f44784fff5488bb59d563ee7ff7b94c08a48c1 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Sun, 19 May 2024 23:41:31 +0200 Subject: use cargo features to enable/disable protocols for net crate --- net/src/stream/mod.rs | 2 ++ net/src/stream/websocket.rs | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'net/src/stream') diff --git a/net/src/stream/mod.rs b/net/src/stream/mod.rs index b792292..ce48a77 100644 --- a/net/src/stream/mod.rs +++ b/net/src/stream/mod.rs @@ -1,6 +1,8 @@ mod buffer; +#[cfg(feature = "ws")] mod websocket; +#[cfg(feature = "ws")] pub use websocket::WsStream; use std::{ diff --git a/net/src/stream/websocket.rs b/net/src/stream/websocket.rs index 2552eaf..9d41626 100644 --- a/net/src/stream/websocket.rs +++ b/net/src/stream/websocket.rs @@ -6,9 +6,9 @@ use std::{ use async_tungstenite::tungstenite::Message; use futures_util::{Sink, SinkExt, Stream, StreamExt}; -#[cfg(feature = "smol")] +#[cfg(all(feature = "smol", feature = "tls"))] use futures_rustls::TlsStream; -#[cfg(feature = "tokio")] +#[cfg(all(feature = "tokio", feature = "tls"))] use tokio_rustls::TlsStream; use karyon_core::async_runtime::net::TcpStream; @@ -37,6 +37,7 @@ where } } + #[cfg(feature = "tls")] pub fn new_wss(conn: WebSocketStream>, codec: C) -> Self { Self { inner: InnerWSConn::Tls(conn), @@ -59,6 +60,7 @@ where enum InnerWSConn { Plain(WebSocketStream), + #[cfg(feature = "tls")] Tls(WebSocketStream>), } @@ -68,6 +70,7 @@ impl Sink for InnerWSConn { fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match &mut *self { InnerWSConn::Plain(s) => Pin::new(s).poll_ready(cx).map_err(Error::from), + #[cfg(feature = "tls")] InnerWSConn::Tls(s) => Pin::new(s).poll_ready(cx).map_err(Error::from), } } @@ -75,6 +78,7 @@ impl Sink for InnerWSConn { fn start_send(mut self: Pin<&mut Self>, item: Message) -> Result<()> { match &mut *self { InnerWSConn::Plain(s) => Pin::new(s).start_send(item).map_err(Error::from), + #[cfg(feature = "tls")] InnerWSConn::Tls(s) => Pin::new(s).start_send(item).map_err(Error::from), } } @@ -82,6 +86,7 @@ impl Sink for InnerWSConn { fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match &mut *self { InnerWSConn::Plain(s) => Pin::new(s).poll_flush(cx).map_err(Error::from), + #[cfg(feature = "tls")] InnerWSConn::Tls(s) => Pin::new(s).poll_flush(cx).map_err(Error::from), } } @@ -89,6 +94,7 @@ impl Sink for InnerWSConn { fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match &mut *self { InnerWSConn::Plain(s) => Pin::new(s).poll_close(cx).map_err(Error::from), + #[cfg(feature = "tls")] InnerWSConn::Tls(s) => Pin::new(s).poll_close(cx).map_err(Error::from), } .map_err(Error::from) @@ -101,6 +107,7 @@ impl Stream for InnerWSConn { fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match &mut *self { InnerWSConn::Plain(s) => Pin::new(s).poll_next(cx).map_err(Error::from), + #[cfg(feature = "tls")] InnerWSConn::Tls(s) => Pin::new(s).poll_next(cx).map_err(Error::from), } } -- cgit v1.2.3