@@ -24,31 +24,31 @@ pub use pipes::Selectable;
2424/// A trait for things that can send multiple messages.
2525pub trait GenericChan < T > {
2626 /// Sends a message.
27- fn send ( x : T ) ;
27+ fn send ( & self , x : T ) ;
2828}
2929
3030/// Things that can send multiple messages and can detect when the receiver
3131/// is closed
3232pub trait GenericSmartChan < T > {
3333 /// 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 ;
3535}
3636
3737/// A trait for things that can receive multiple messages.
3838pub trait GenericPort < T > {
3939 /// Receives a message, or fails if the connection closes.
40- fn recv ( ) -> T ;
40+ fn recv ( & self ) -> T ;
4141
4242 /** Receives a message, or returns `none` if
4343 the connection is closed or closes.
4444 */
45- fn try_recv ( ) -> Option < T > ;
45+ fn try_recv ( & self ) -> Option < T > ;
4646}
4747
4848/// Ports that can `peek`
4949pub trait Peekable < T > {
5050 /// Returns true if a message is available
51- pure fn peek ( ) -> bool ;
51+ pure fn peek ( & self ) -> bool ;
5252}
5353
5454/// Returns the index of an endpoint that is ready to receive.
@@ -105,7 +105,7 @@ pub fn stream<T:Owned>() -> (Port<T>, Chan<T>) {
105105}
106106
107107impl<T: Owned> GenericChan<T> for Chan<T> {
108- fn send(x: T) {
108+ fn send(&self, x: T) {
109109 let mut endp = None;
110110 endp <-> self.endp;
111111 self.endp = Some(
@@ -115,7 +115,7 @@ impl<T: Owned> GenericChan<T> for Chan<T> {
115115
116116impl<T: Owned> GenericSmartChan<T> for Chan<T> {
117117
118- fn try_send(x: T) -> bool {
118+ fn try_send(&self, x: T) -> bool {
119119 let mut endp = None;
120120 endp <-> self.endp;
121121 match streamp::client::try_data(unwrap(endp), x) {
@@ -129,15 +129,15 @@ impl<T: Owned> GenericSmartChan<T> for Chan<T> {
129129}
130130
131131impl<T: Owned> GenericPort<T> for Port<T> {
132- fn recv() -> T {
132+ fn recv(&self ) -> T {
133133 let mut endp = None;
134134 endp <-> self.endp;
135135 let streamp::data(x, endp) = recv(unwrap(endp));
136136 self.endp = Some(endp);
137137 x
138138 }
139139
140- fn try_recv() -> Option<T> {
140+ fn try_recv(&self ) -> Option<T> {
141141 let mut endp = None;
142142 endp <-> self.endp;
143143 match try_recv(unwrap(endp)) {
@@ -151,7 +151,7 @@ impl<T: Owned> GenericPort<T> for Port<T> {
151151}
152152
153153impl<T: Owned> Peekable<T> for Port<T> {
154- pure fn peek() -> bool {
154+ pure fn peek(&self ) -> bool {
155155 unsafe {
156156 let mut endp = None;
157157 endp <-> self.endp;
@@ -166,7 +166,7 @@ impl<T: Owned> Peekable<T> for Port<T> {
166166}
167167
168168impl<T: Owned> Selectable for Port<T> {
169- pure fn header() -> *PacketHeader {
169+ pure fn header(&self ) -> *PacketHeader {
170170 unsafe {
171171 match self.endp {
172172 Some(ref endp) => endp.header(),
@@ -189,11 +189,11 @@ pub fn PortSet<T: Owned>() -> PortSet<T>{
189189
190190pub impl<T: Owned> PortSet<T> {
191191
192- fn add(port: Port<T>) {
192+ fn add(&self, port: Port<T>) {
193193 self.ports.push(port)
194194 }
195195
196- fn chan() -> Chan<T> {
196+ fn chan(&self ) -> Chan<T> {
197197 let (po, ch) = stream();
198198 self.add(po);
199199 ch
@@ -202,7 +202,7 @@ pub impl<T: Owned> PortSet<T> {
202202
203203impl<T: Owned> GenericPort<T> for PortSet<T> {
204204
205- fn try_recv() -> Option<T> {
205+ fn try_recv(&self ) -> Option<T> {
206206 let mut result = None;
207207 // we have to swap the ports array so we aren't borrowing
208208 // aliasable mutable memory.
@@ -224,14 +224,14 @@ impl<T: Owned> GenericPort<T> for PortSet<T> {
224224 result
225225 }
226226
227- fn recv() -> T {
227+ fn recv(&self ) -> T {
228228 self.try_recv().expect(" port_set: endpoints closed")
229229 }
230230
231231}
232232
233233impl<T: Owned> Peekable<T> for PortSet<T> {
234- pure fn peek() -> bool {
234+ pure fn peek(&self ) -> bool {
235235 // It'd be nice to use self.port.each, but that version isn't
236236 // pure.
237237 for vec::each(self.ports) |p| {
@@ -245,7 +245,7 @@ impl<T: Owned> Peekable<T> for PortSet<T> {
245245pub type SharedChan<T> = unstable::Exclusive<Chan<T>>;
246246
247247impl<T: Owned> GenericChan<T> for SharedChan<T> {
248- fn send(x: T) {
248+ fn send(&self, x: T) {
249249 let mut xx = Some(x);
250250 do self.with_imm |chan| {
251251 let mut x = None;
@@ -256,7 +256,7 @@ impl<T: Owned> GenericChan<T> for SharedChan<T> {
256256}
257257
258258impl<T: Owned> GenericSmartChan<T> for SharedChan<T> {
259- fn try_send(x: T) -> bool {
259+ fn try_send(&self, x: T) -> bool {
260260 let mut xx = Some(x);
261261 do self.with_imm |chan| {
262262 let mut x = None;
@@ -274,27 +274,27 @@ pub fn SharedChan<T:Owned>(c: Chan<T>) -> SharedChan<T> {
274274/// Receive a message from one of two endpoints.
275275pub trait Select2<T: Owned, U: Owned> {
276276 /// 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>>;
278278 /// Receive a message or fail if a connection closes.
279- fn select() -> Either<T, U>;
279+ fn select(&self ) -> Either<T, U>;
280280}
281281
282282impl<T: Owned, U: Owned,
283283 Left: Selectable + GenericPort<T>,
284284 Right: Selectable + GenericPort<U>>
285285 Select2<T, U> for (Left, Right) {
286286
287- fn select() -> Either<T, U> {
288- match self {
287+ fn select(&self ) -> Either<T, U> {
288+ match * self {
289289 (ref lp, ref rp) => match select2i(lp, rp) {
290290 Left(()) => Left (lp.recv()),
291291 Right(()) => Right(rp.recv())
292292 }
293293 }
294294 }
295295
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 {
298298 (ref lp, ref rp) => match select2i(lp, rp) {
299299 Left(()) => Left (lp.try_recv()),
300300 Right(()) => Right(rp.try_recv())
0 commit comments