From 8ebdb37fd24435d08451625656cc53ebc814c3fa Mon Sep 17 00:00:00 2001 From: Ben Blum Date: Mon, 5 Aug 2013 19:58:10 -0400 Subject: fix recv_ready for Port to take &self and not need to return a tuple. Close #8192. --- src/libstd/rt/comm.rs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/libstd/rt/comm.rs') diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs index 0cf223f3029..6dc44dd1193 100644 --- a/src/libstd/rt/comm.rs +++ b/src/libstd/rt/comm.rs @@ -508,7 +508,11 @@ impl Peekable for Port { } } -impl Select for Port { +// XXX: Kind of gross. A Port should be selectable so you can make an array +// of them, but a &Port should also be selectable so you can select2 on it +// alongside a PortOne without passing the port by value in recv_ready. + +impl<'self, T> Select for &'self Port { #[inline] fn optimistic_check(&mut self) -> bool { do self.next.with_mut_ref |pone| { pone.optimistic_check() } @@ -526,12 +530,29 @@ impl Select for Port { } } -impl SelectPort<(T, Port)> for Port { - fn recv_ready(self) -> Option<(T, Port)> { +impl Select for Port { + #[inline] + fn optimistic_check(&mut self) -> bool { + (&*self).optimistic_check() + } + + #[inline] + fn block_on(&mut self, sched: &mut Scheduler, task: BlockedTask) -> bool { + (&*self).block_on(sched, task) + } + + #[inline] + fn unblock_from(&mut self) -> bool { + (&*self).unblock_from() + } +} + +impl<'self, T> SelectPort for &'self Port { + fn recv_ready(self) -> Option { match self.next.take().recv_ready() { Some(StreamPayload { val, next }) => { self.next.put_back(next); - Some((val, self)) + Some(val) } None => None } -- cgit 1.4.1-3-g733a5