Skip to content

Commit b1ae2c3

Browse files
committed
feat: rollback to generic type for session
1 parent e710e8c commit b1ae2c3

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "net-mux"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
authors = ["Poseidon <18646154381@163.com>"]
55
edition = "2024"
66
description = "A Net Stream Multiplexing Library"

src/session/mod.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
mod stream_manager;
2828
mod task;
2929

30+
use std::marker::PhantomData;
3031
use std::sync::{
3132
Arc,
3233
atomic::{AtomicBool, Ordering},
@@ -52,7 +53,7 @@ use crate::{
5253
/// `Session` is the core component of network multiplexing, managing multiple independent streams
5354
/// over a single underlying connection. Each session can handle multiple streams simultaneously,
5455
/// with each stream having its own unique stream ID and lifecycle.
55-
pub struct Session {
56+
pub struct Session<T: AsyncRead + AsyncWrite + Send + Unpin + 'static> {
5657
config: Config,
5758
stream_id_allocator: StreamIdAllocator,
5859
stream_manager: Arc<StreamManager>,
@@ -66,13 +67,12 @@ pub struct Session {
6667
// contains here to copy to new Stream
6768
msg_tx: mpsc::UnboundedSender<Message>,
6869
close_tx: mpsc::UnboundedSender<StreamId>,
70+
71+
_phantom: PhantomData<T>,
6972
}
7073

71-
impl Session {
72-
fn new<T>(conn: T, config: Config, mode: SessionMode) -> Self
73-
where
74-
T: AsyncRead + AsyncWrite + Send + Unpin + 'static,
75-
{
74+
impl<T: AsyncRead + AsyncWrite + Send + Unpin + 'static> Session<T> {
75+
fn new(conn: T, config: Config, mode: SessionMode) -> Self {
7676
let (conn_reader, conn_writer) = io::split(conn);
7777
let (msg_tx, msg_rx) = mpsc::unbounded_channel();
7878
let (close_tx, close_rx) = mpsc::unbounded_channel();
@@ -94,6 +94,7 @@ impl Session {
9494
is_shutdown: AtomicBool::new(false),
9595
msg_tx,
9696
close_tx,
97+
_phantom: PhantomData,
9798
};
9899

99100
tokio::spawn(task::start_msg_collect_loop(
@@ -116,18 +117,12 @@ impl Session {
116117
}
117118

118119
/// Create a server session.
119-
pub fn server<T>(conn: T, config: Config) -> Self
120-
where
121-
T: AsyncRead + AsyncWrite + Send + Unpin + 'static,
122-
{
120+
pub fn server(conn: T, config: Config) -> Self {
123121
Self::new(conn, config, SERVER_MODE)
124122
}
125123

126124
/// Create a client session.
127-
pub fn client<T>(conn: T, config: Config) -> Self
128-
where
129-
T: AsyncRead + AsyncWrite + Send + Unpin + 'static,
130-
{
125+
pub fn client(conn: T, config: Config) -> Self {
131126
Self::new(conn, config, CLIENT_MODE)
132127
}
133128

0 commit comments

Comments
 (0)