From 96b41b552ad3d84b5d67fe953c5036a787f3e946 Mon Sep 17 00:00:00 2001 From: YinMo19 Date: Sun, 27 Apr 2025 16:50:43 +0800 Subject: [PATCH] [enhance] add from method --- src/stream.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/stream.rs b/src/stream.rs index fcac31d..987d9be 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -1,6 +1,7 @@ use crate::{config, tcp, websocket, ResultType}; use sodiumoxide::crypto::secretbox::Key; use std::net::SocketAddr; +use tokio::net::TcpStream; // support Websocket and tcp. pub enum Stream { @@ -107,4 +108,9 @@ impl Stream { Self::Tcp(tcp) => tcp.local_addr(), } } + + #[inline] + pub fn from(stream: TcpStream, stream_addr: SocketAddr) -> Self { + Self::Tcp(tcp::FramedStream::from(stream, stream_addr)) + } }