[enhance] add from method

This commit is contained in:
YinMo19 2025-04-27 16:50:43 +08:00
parent d04ae289c8
commit 96b41b552a

View File

@ -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))
}
}