diff options
| author | Ryan Scheel (Havvy) <ryan.havvy@gmail.com> | 2014-03-22 17:50:59 -0700 |
|---|---|---|
| committer | Ryan Scheel (Havvy) <ryan.havvy@gmail.com> | 2014-03-22 17:50:59 -0700 |
| commit | f62bdfc134c1f41eeaf87b853a10c8bc132822fb (patch) | |
| tree | 12d153495646cfd5583c4f6a01e228e5bbd7accb /src/libsync | |
| parent | a73d2c70d4c24b85f3846d79b241ba1eb5f95e23 (diff) | |
| download | rust-f62bdfc134c1f41eeaf87b853a10c8bc132822fb.tar.gz rust-f62bdfc134c1f41eeaf87b853a10c8bc132822fb.zip | |
Change types T,U to R (recv), S (sender) in libsync/comm.rs
Diffstat (limited to 'src/libsync')
| -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, |
