@@ -19,68 +19,68 @@ Higher level communication abstractions.
1919use std:: comm;
2020
2121/// An extension of `pipes::stream` that allows both sending and receiving.
22- pub struct DuplexStream < T , U > {
23- priv tx: Sender < T > ,
24- priv rx: Receiver < U > ,
22+ pub struct DuplexStream < S , R > {
23+ priv tx: Sender < S > ,
24+ priv rx: Receiver < R > ,
2525}
2626
2727/// Creates a bidirectional stream.
28- pub fn duplex < T : Send , U : Send > ( ) -> ( DuplexStream < T , U > , DuplexStream < U , T > ) {
28+ pub fn duplex < S : Send , R : Send > ( ) -> ( DuplexStream < S , R > , DuplexStream < R , S > ) {
2929 let ( tx1, rx1) = channel ( ) ;
3030 let ( tx2, rx2) = channel ( ) ;
3131 ( DuplexStream { tx : tx1, rx : rx2 } ,
3232 DuplexStream { tx : tx2, rx : rx1 } )
3333}
3434
3535// Allow these methods to be used without import:
36- impl < T : Send , U : Send > DuplexStream < T , U > {
37- pub fn send ( & self , x : T ) {
36+ impl < S : Send , R : Send > DuplexStream < S , R > {
37+ pub fn send ( & self , x : S ) {
3838 self . tx . send ( x)
3939 }
40- pub fn try_send ( & self , x : T ) -> bool {
40+ pub fn try_send ( & self , x : S ) -> bool {
4141 self . tx . try_send ( x)
4242 }
43- pub fn recv ( & self ) -> U {
43+ pub fn recv ( & self ) -> R {
4444 self . rx . recv ( )
4545 }
46- pub fn try_recv ( & self ) -> comm:: TryRecvResult < U > {
46+ pub fn try_recv ( & self ) -> comm:: TryRecvResult < R > {
4747 self . rx . try_recv ( )
4848 }
49- pub fn recv_opt ( & self ) -> Option < U > {
49+ pub fn recv_opt ( & self ) -> Option < R > {
5050 self . rx . recv_opt ( )
5151 }
5252}
5353
5454/// An extension of `pipes::stream` that provides synchronous message sending.
55- pub struct SyncSender < T > { priv duplex_stream : DuplexStream < T , ( ) > }
55+ pub struct SyncSender < S > { priv duplex_stream : DuplexStream < S , ( ) > }
5656/// An extension of `pipes::stream` that acknowledges each message received.
57- pub struct SyncReceiver < T > { priv duplex_stream : DuplexStream < ( ) , T > }
57+ pub struct SyncReceiver < R > { priv duplex_stream : DuplexStream < ( ) , R > }
5858
59- impl < T : Send > SyncSender < T > {
60- pub fn send ( & self , val : T ) {
59+ impl < S : Send > SyncSender < S > {
60+ pub fn send ( & self , val : S ) {
6161 assert ! ( self . try_send( val) , "SyncSender.send: receiving port closed" ) ;
6262 }
6363
6464 /// Sends a message, or report if the receiver has closed the connection
6565 /// before receiving.
66- pub fn try_send ( & self , val : T ) -> bool {
66+ pub fn try_send ( & self , val : S ) -> bool {
6767 self . duplex_stream . try_send ( val) && self . duplex_stream . recv_opt ( ) . is_some ( )
6868 }
6969}
7070
71- impl < T : Send > SyncReceiver < T > {
72- pub fn recv ( & self ) -> T {
71+ impl < R : Send > SyncReceiver < R > {
72+ pub fn recv ( & self ) -> R {
7373 self . recv_opt ( ) . expect ( "SyncReceiver.recv: sending channel closed" )
7474 }
7575
76- pub fn recv_opt ( & self ) -> Option < T > {
76+ pub fn recv_opt ( & self ) -> Option < R > {
7777 self . duplex_stream . recv_opt ( ) . map ( |val| {
7878 self . duplex_stream . try_send ( ( ) ) ;
7979 val
8080 } )
8181 }
8282
83- pub fn try_recv ( & self ) -> comm:: TryRecvResult < T > {
83+ pub fn try_recv ( & self ) -> comm:: TryRecvResult < R > {
8484 match self . duplex_stream . try_recv ( ) {
8585 comm:: Data ( t) => { self . duplex_stream . try_send ( ( ) ) ; comm:: Data ( t) }
8686 state => state,
0 commit comments