diff --git a/src/libsync/comm.rs b/src/libsync/comm.rs index f713c13d945..aecea37cce8 100644 --- a/src/libsync/comm.rs +++ b/src/libsync/comm.rs @@ -19,13 +19,13 @@ Higher level communication abstractions. use std::comm; /// An extension of `pipes::stream` that allows both sending and receiving. -pub struct DuplexStream { - priv tx: Sender, - priv rx: Receiver, +pub struct DuplexStream { + priv tx: Sender, + priv rx: Receiver, } /// Creates a bidirectional stream. -pub fn duplex() -> (DuplexStream, DuplexStream) { +pub fn duplex() -> (DuplexStream, DuplexStream) { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); (DuplexStream { tx: tx1, rx: rx2 }, @@ -33,54 +33,54 @@ pub fn duplex() -> (DuplexStream, DuplexStream) { } // Allow these methods to be used without import: -impl DuplexStream { - pub fn send(&self, x: T) { +impl DuplexStream { + pub fn send(&self, x: S) { self.tx.send(x) } - pub fn try_send(&self, x: T) -> bool { + pub fn try_send(&self, x: S) -> bool { self.tx.try_send(x) } - pub fn recv(&self) -> U { + pub fn recv(&self) -> R { self.rx.recv() } - pub fn try_recv(&self) -> comm::TryRecvResult { + pub fn try_recv(&self) -> comm::TryRecvResult { self.rx.try_recv() } - pub fn recv_opt(&self) -> Option { + pub fn recv_opt(&self) -> Option { self.rx.recv_opt() } } /// An extension of `pipes::stream` that provides synchronous message sending. -pub struct SyncSender { priv duplex_stream: DuplexStream } +pub struct SyncSender { priv duplex_stream: DuplexStream } /// An extension of `pipes::stream` that acknowledges each message received. -pub struct SyncReceiver { priv duplex_stream: DuplexStream<(), T> } +pub struct SyncReceiver { priv duplex_stream: DuplexStream<(), R> } -impl SyncSender { - pub fn send(&self, val: T) { +impl SyncSender { + pub fn send(&self, val: S) { assert!(self.try_send(val), "SyncSender.send: receiving port closed"); } /// Sends a message, or report if the receiver has closed the connection /// before receiving. - pub fn try_send(&self, val: T) -> bool { + pub fn try_send(&self, val: S) -> bool { self.duplex_stream.try_send(val) && self.duplex_stream.recv_opt().is_some() } } -impl SyncReceiver { - pub fn recv(&self) -> T { +impl SyncReceiver { + pub fn recv(&self) -> R { self.recv_opt().expect("SyncReceiver.recv: sending channel closed") } - pub fn recv_opt(&self) -> Option { + pub fn recv_opt(&self) -> Option { self.duplex_stream.recv_opt().map(|val| { self.duplex_stream.try_send(()); val }) } - pub fn try_recv(&self) -> comm::TryRecvResult { + pub fn try_recv(&self) -> comm::TryRecvResult { match self.duplex_stream.try_recv() { comm::Data(t) => { self.duplex_stream.try_send(()); comm::Data(t) } state => state,