diff options
| author | Flavio Percoco <flaper87@gmail.com> | 2013-09-14 22:50:28 +0200 |
|---|---|---|
| committer | Flavio Percoco <flaper87@gmail.com> | 2013-09-14 22:50:28 +0200 |
| commit | 9357f8f4cdc6d3a7c454d0b2e3ffbaad997f315e (patch) | |
| tree | 7963f4ee0a2302dcecd11887c91ea06f80cfd083 /src/libstd | |
| parent | bca015d9ffd94c36fc8e1b4f30727f71e5ce579f (diff) | |
| download | rust-9357f8f4cdc6d3a7c454d0b2e3ffbaad997f315e.tar.gz rust-9357f8f4cdc6d3a7c454d0b2e3ffbaad997f315e.zip | |
Add SharedPort wrapper around rt::comm::SharedPort
SharedPort implementation was missing in std::comm. Since this module also wraps SharedChan, it makes sense to have SharedPort defined there as well.
Diffstat (limited to 'src/libstd')
| -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() } + } +} |
