2727mod stream_manager;
2828mod task;
2929
30+ use std:: marker:: PhantomData ;
3031use 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