@@ -19,68 +19,68 @@ Higher level communication abstractions.
19
19
use std:: comm;
20
20
21
21
/// 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 > ,
25
25
}
26
26
27
27
/// 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 > ) {
29
29
let ( tx1, rx1) = channel ( ) ;
30
30
let ( tx2, rx2) = channel ( ) ;
31
31
( DuplexStream { tx : tx1, rx : rx2 } ,
32
32
DuplexStream { tx : tx2, rx : rx1 } )
33
33
}
34
34
35
35
// 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 ) {
38
38
self . tx . send ( x)
39
39
}
40
- pub fn try_send ( & self , x : T ) -> bool {
40
+ pub fn try_send ( & self , x : S ) -> bool {
41
41
self . tx . try_send ( x)
42
42
}
43
- pub fn recv ( & self ) -> U {
43
+ pub fn recv ( & self ) -> R {
44
44
self . rx . recv ( )
45
45
}
46
- pub fn try_recv ( & self ) -> comm:: TryRecvResult < U > {
46
+ pub fn try_recv ( & self ) -> comm:: TryRecvResult < R > {
47
47
self . rx . try_recv ( )
48
48
}
49
- pub fn recv_opt ( & self ) -> Option < U > {
49
+ pub fn recv_opt ( & self ) -> Option < R > {
50
50
self . rx . recv_opt ( )
51
51
}
52
52
}
53
53
54
54
/// 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 , ( ) > }
56
56
/// 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 > }
58
58
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 ) {
61
61
assert ! ( self . try_send( val) , "SyncSender.send: receiving port closed" ) ;
62
62
}
63
63
64
64
/// Sends a message, or report if the receiver has closed the connection
65
65
/// before receiving.
66
- pub fn try_send ( & self , val : T ) -> bool {
66
+ pub fn try_send ( & self , val : S ) -> bool {
67
67
self . duplex_stream . try_send ( val) && self . duplex_stream . recv_opt ( ) . is_some ( )
68
68
}
69
69
}
70
70
71
- impl < T : Send > SyncReceiver < T > {
72
- pub fn recv ( & self ) -> T {
71
+ impl < R : Send > SyncReceiver < R > {
72
+ pub fn recv ( & self ) -> R {
73
73
self . recv_opt ( ) . expect ( "SyncReceiver.recv: sending channel closed" )
74
74
}
75
75
76
- pub fn recv_opt ( & self ) -> Option < T > {
76
+ pub fn recv_opt ( & self ) -> Option < R > {
77
77
self . duplex_stream . recv_opt ( ) . map ( |val| {
78
78
self . duplex_stream . try_send ( ( ) ) ;
79
79
val
80
80
} )
81
81
}
82
82
83
- pub fn try_recv ( & self ) -> comm:: TryRecvResult < T > {
83
+ pub fn try_recv ( & self ) -> comm:: TryRecvResult < R > {
84
84
match self . duplex_stream . try_recv ( ) {
85
85
comm:: Data ( t) => { self . duplex_stream . try_send ( ( ) ) ; comm:: Data ( t) }
86
86
state => state,
0 commit comments