@@ -24,31 +24,31 @@ pub use pipes::Selectable;
24
24
/// A trait for things that can send multiple messages.
25
25
pub trait GenericChan < T > {
26
26
/// Sends a message.
27
- fn send ( x : T ) ;
27
+ fn send ( & self , x : T ) ;
28
28
}
29
29
30
30
/// Things that can send multiple messages and can detect when the receiver
31
31
/// is closed
32
32
pub trait GenericSmartChan < T > {
33
33
/// Sends a message, or report if the receiver has closed the connection.
34
- fn try_send ( x : T ) -> bool ;
34
+ fn try_send ( & self , x : T ) -> bool ;
35
35
}
36
36
37
37
/// A trait for things that can receive multiple messages.
38
38
pub trait GenericPort < T > {
39
39
/// Receives a message, or fails if the connection closes.
40
- fn recv ( ) -> T ;
40
+ fn recv ( & self ) -> T ;
41
41
42
42
/** Receives a message, or returns `none` if
43
43
the connection is closed or closes.
44
44
*/
45
- fn try_recv ( ) -> Option < T > ;
45
+ fn try_recv ( & self ) -> Option < T > ;
46
46
}
47
47
48
48
/// Ports that can `peek`
49
49
pub trait Peekable < T > {
50
50
/// Returns true if a message is available
51
- pure fn peek ( ) -> bool ;
51
+ pure fn peek ( & self ) -> bool ;
52
52
}
53
53
54
54
/// Returns the index of an endpoint that is ready to receive.
@@ -105,7 +105,7 @@ pub fn stream<T:Owned>() -> (Port<T>, Chan<T>) {
105
105
}
106
106
107
107
impl<T: Owned> GenericChan<T> for Chan<T> {
108
- fn send(x: T) {
108
+ fn send(&self, x: T) {
109
109
let mut endp = None;
110
110
endp <-> self.endp;
111
111
self.endp = Some(
@@ -115,7 +115,7 @@ impl<T: Owned> GenericChan<T> for Chan<T> {
115
115
116
116
impl<T: Owned> GenericSmartChan<T> for Chan<T> {
117
117
118
- fn try_send(x: T) -> bool {
118
+ fn try_send(&self, x: T) -> bool {
119
119
let mut endp = None;
120
120
endp <-> self.endp;
121
121
match streamp::client::try_data(unwrap(endp), x) {
@@ -129,15 +129,15 @@ impl<T: Owned> GenericSmartChan<T> for Chan<T> {
129
129
}
130
130
131
131
impl<T: Owned> GenericPort<T> for Port<T> {
132
- fn recv() -> T {
132
+ fn recv(&self ) -> T {
133
133
let mut endp = None;
134
134
endp <-> self.endp;
135
135
let streamp::data(x, endp) = recv(unwrap(endp));
136
136
self.endp = Some(endp);
137
137
x
138
138
}
139
139
140
- fn try_recv() -> Option<T> {
140
+ fn try_recv(&self ) -> Option<T> {
141
141
let mut endp = None;
142
142
endp <-> self.endp;
143
143
match try_recv(unwrap(endp)) {
@@ -151,7 +151,7 @@ impl<T: Owned> GenericPort<T> for Port<T> {
151
151
}
152
152
153
153
impl<T: Owned> Peekable<T> for Port<T> {
154
- pure fn peek() -> bool {
154
+ pure fn peek(&self ) -> bool {
155
155
unsafe {
156
156
let mut endp = None;
157
157
endp <-> self.endp;
@@ -166,7 +166,7 @@ impl<T: Owned> Peekable<T> for Port<T> {
166
166
}
167
167
168
168
impl<T: Owned> Selectable for Port<T> {
169
- pure fn header() -> *PacketHeader {
169
+ pure fn header(&self ) -> *PacketHeader {
170
170
unsafe {
171
171
match self.endp {
172
172
Some(ref endp) => endp.header(),
@@ -189,11 +189,11 @@ pub fn PortSet<T: Owned>() -> PortSet<T>{
189
189
190
190
pub impl<T: Owned> PortSet<T> {
191
191
192
- fn add(port: Port<T>) {
192
+ fn add(&self, port: Port<T>) {
193
193
self.ports.push(port)
194
194
}
195
195
196
- fn chan() -> Chan<T> {
196
+ fn chan(&self ) -> Chan<T> {
197
197
let (po, ch) = stream();
198
198
self.add(po);
199
199
ch
@@ -202,7 +202,7 @@ pub impl<T: Owned> PortSet<T> {
202
202
203
203
impl<T: Owned> GenericPort<T> for PortSet<T> {
204
204
205
- fn try_recv() -> Option<T> {
205
+ fn try_recv(&self ) -> Option<T> {
206
206
let mut result = None;
207
207
// we have to swap the ports array so we aren't borrowing
208
208
// aliasable mutable memory.
@@ -224,14 +224,14 @@ impl<T: Owned> GenericPort<T> for PortSet<T> {
224
224
result
225
225
}
226
226
227
- fn recv() -> T {
227
+ fn recv(&self ) -> T {
228
228
self.try_recv().expect(" port_set: endpoints closed")
229
229
}
230
230
231
231
}
232
232
233
233
impl<T: Owned> Peekable<T> for PortSet<T> {
234
- pure fn peek() -> bool {
234
+ pure fn peek(&self ) -> bool {
235
235
// It'd be nice to use self.port.each, but that version isn't
236
236
// pure.
237
237
for vec::each(self.ports) |p| {
@@ -245,7 +245,7 @@ impl<T: Owned> Peekable<T> for PortSet<T> {
245
245
pub type SharedChan<T> = unstable::Exclusive<Chan<T>>;
246
246
247
247
impl<T: Owned> GenericChan<T> for SharedChan<T> {
248
- fn send(x: T) {
248
+ fn send(&self, x: T) {
249
249
let mut xx = Some(x);
250
250
do self.with_imm |chan| {
251
251
let mut x = None;
@@ -256,7 +256,7 @@ impl<T: Owned> GenericChan<T> for SharedChan<T> {
256
256
}
257
257
258
258
impl<T: Owned> GenericSmartChan<T> for SharedChan<T> {
259
- fn try_send(x: T) -> bool {
259
+ fn try_send(&self, x: T) -> bool {
260
260
let mut xx = Some(x);
261
261
do self.with_imm |chan| {
262
262
let mut x = None;
@@ -274,27 +274,27 @@ pub fn SharedChan<T:Owned>(c: Chan<T>) -> SharedChan<T> {
274
274
/// Receive a message from one of two endpoints.
275
275
pub trait Select2<T: Owned, U: Owned> {
276
276
/// Receive a message or return `None` if a connection closes.
277
- fn try_select() -> Either<Option<T>, Option<U>>;
277
+ fn try_select(&self ) -> Either<Option<T>, Option<U>>;
278
278
/// Receive a message or fail if a connection closes.
279
- fn select() -> Either<T, U>;
279
+ fn select(&self ) -> Either<T, U>;
280
280
}
281
281
282
282
impl<T: Owned, U: Owned,
283
283
Left: Selectable + GenericPort<T>,
284
284
Right: Selectable + GenericPort<U>>
285
285
Select2<T, U> for (Left, Right) {
286
286
287
- fn select() -> Either<T, U> {
288
- match self {
287
+ fn select(&self ) -> Either<T, U> {
288
+ match * self {
289
289
(ref lp, ref rp) => match select2i(lp, rp) {
290
290
Left(()) => Left (lp.recv()),
291
291
Right(()) => Right(rp.recv())
292
292
}
293
293
}
294
294
}
295
295
296
- fn try_select() -> Either<Option<T>, Option<U>> {
297
- match self {
296
+ fn try_select(&self ) -> Either<Option<T>, Option<U>> {
297
+ match * self {
298
298
(ref lp, ref rp) => match select2i(lp, rp) {
299
299
Left(()) => Left (lp.try_recv()),
300
300
Right(()) => Right(rp.try_recv())
0 commit comments