diff options
| author | bors <bors@rust-lang.org> | 2014-03-23 06:06:54 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-03-23 06:06:54 -0700 |
| commit | 1cd0a5ed268e54c5ba935adc01f9cb0e6bc0348f (patch) | |
| tree | 652906c83c7675244043373e6fb32f6e840315ed | |
| parent | 06be5f7c44e255315a12f97b746307df82bb5390 (diff) | |
| parent | f62bdfc134c1f41eeaf87b853a10c8bc132822fb (diff) | |
| download | rust-1cd0a5ed268e54c5ba935adc01f9cb0e6bc0348f.tar.gz rust-1cd0a5ed268e54c5ba935adc01f9cb0e6bc0348f.zip | |
auto merge of #13093 : Havvy/rust/master, r=sfackler
This will make the types more readable in the documentation, since the letters correspond with what you should either be sending or expecting to receive.
| -rw-r--r-- | src/libsync/comm.rs | 38 |
1 files changed, 19 insertions, 19 deletions
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<T, U> { - priv tx: Sender<T>, - priv rx: Receiver<U>, +pub struct DuplexStream<S, R> { + priv tx: Sender<S>, + priv rx: Receiver<R>, } /// Creates a bidirectional stream. -pub fn duplex<T: Send, U: Send>() -> (DuplexStream<T, U>, DuplexStream<U, T>) { +pub fn duplex<S: Send, R: Send>() -> (DuplexStream<S, R>, DuplexStream<R, S>) { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); (DuplexStream { tx: tx1, rx: rx2 }, @@ -33,54 +33,54 @@ pub fn duplex<T: Send, U: Send>() -> (DuplexStream<T, U>, DuplexStream<U, T>) { } // Allow these methods to be used without import: -impl<T:Send,U:Send> DuplexStream<T, U> { - pub fn send(&self, x: T) { +impl<S:Send,R:Send> DuplexStream<S, R> { + 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<U> { + pub fn try_recv(&self) -> comm::TryRecvResult<R> { self.rx.try_recv() } - pub fn recv_opt(&self) -> Option<U> { + pub fn recv_opt(&self) -> Option<R> { self.rx.recv_opt() } } /// An extension of `pipes::stream` that provides synchronous message sending. -pub struct SyncSender<T> { priv duplex_stream: DuplexStream<T, ()> } +pub struct SyncSender<S> { priv duplex_stream: DuplexStream<S, ()> } /// An extension of `pipes::stream` that acknowledges each message received. -pub struct SyncReceiver<T> { priv duplex_stream: DuplexStream<(), T> } +pub struct SyncReceiver<R> { priv duplex_stream: DuplexStream<(), R> } -impl<T: Send> SyncSender<T> { - pub fn send(&self, val: T) { +impl<S: Send> SyncSender<S> { + 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<T: Send> SyncReceiver<T> { - pub fn recv(&self) -> T { +impl<R: Send> SyncReceiver<R> { + pub fn recv(&self) -> R { self.recv_opt().expect("SyncReceiver.recv: sending channel closed") } - pub fn recv_opt(&self) -> Option<T> { + pub fn recv_opt(&self) -> Option<R> { self.duplex_stream.recv_opt().map(|val| { self.duplex_stream.try_send(()); val }) } - pub fn try_recv(&self) -> comm::TryRecvResult<T> { + pub fn try_recv(&self) -> comm::TryRecvResult<R> { match self.duplex_stream.try_recv() { comm::Data(t) => { self.duplex_stream.try_send(()); comm::Data(t) } state => state, |
