diff options
| author | bors <bors@rust-lang.org> | 2013-09-14 15:20:50 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-09-14 15:20:50 -0700 |
| commit | cf7e93ff2571140abf299212ec9ebc0fcd9944eb (patch) | |
| tree | 3023658ae15090a3d5344a08ec5a5c3c5c3ea814 | |
| parent | 5c4f65e6f593ed790a9d6328c9ff0093572e87ef (diff) | |
| parent | 9357f8f4cdc6d3a7c454d0b2e3ffbaad997f315e (diff) | |
| download | rust-cf7e93ff2571140abf299212ec9ebc0fcd9944eb.tar.gz rust-cf7e93ff2571140abf299212ec9ebc0fcd9944eb.zip | |
auto merge of #9198 : FlaPer87/rust/shared-port, r=cmr
SharedPort implementation was missing in std::comm. Since this module also wraps SharedChan, it makes sense to have SharedPort defined there as well.
| -rw-r--r-- | src/libstd/comm.rs | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/src/libstd/comm.rs b/src/libstd/comm.rs index 18c7674873f..ec8314795ac 100644 --- a/src/libstd/comm.rs +++ b/src/libstd/comm.rs @@ -66,15 +66,6 @@ pub fn stream<T: Send>() -> (Port<T>, Chan<T>) { (Port { x: p }, Chan { x: c }) } -pub struct SharedChan<T> { x: rtcomm::SharedChan<T> } - -impl<T: Send> SharedChan<T> { - pub fn new(c: Chan<T>) -> SharedChan<T> { - let Chan { x: c } = c; - SharedChan { x: rtcomm::SharedChan::new(c) } - } -} - impl<T: Send> ChanOne<T> { pub fn send(self, val: T) { let ChanOne { x: c } = self; @@ -161,6 +152,16 @@ impl<T: Send> Peekable<T> for Port<T> { } } + +pub struct SharedChan<T> { x: rtcomm::SharedChan<T> } + +impl<T: Send> SharedChan<T> { + pub fn new(c: Chan<T>) -> SharedChan<T> { + let Chan { x: c } = c; + SharedChan { x: rtcomm::SharedChan::new(c) } + } +} + impl<T: Send> GenericChan<T> for SharedChan<T> { fn send(&self, val: T) { let &SharedChan { x: ref c } = self; @@ -193,3 +194,31 @@ impl<T> Clone for SharedChan<T> { SharedChan { x: c.clone() } } } + +pub struct SharedPort<T> { x: rtcomm::SharedPort<T> } + +impl<T: Send> SharedPort<T> { + pub fn new(p: Port<T>) -> SharedPort<T> { + let Port { x: p } = p; + SharedPort { x: rtcomm::SharedPort::new(p) } + } +} + +impl<T: Send> GenericPort<T> for SharedPort<T> { + fn recv(&self) -> T { + let &SharedPort { x: ref p } = self; + p.recv() + } + + fn try_recv(&self) -> Option<T> { + let &SharedPort { x: ref p } = self; + p.try_recv() + } +} + +impl<T> Clone for SharedPort<T> { + fn clone(&self) -> SharedPort<T> { + let &SharedPort { x: ref p } = self; + SharedPort { x: p.clone() } + } +} |
