diff options
| author | Eric Holk <eric.holk@gmail.com> | 2012-07-13 15:39:31 -0700 |
|---|---|---|
| committer | Eric Holk <eric.holk@gmail.com> | 2012-07-16 14:50:46 -0700 |
| commit | 436d263aed2ef54cdcec84ecb9c99a71b487769e (patch) | |
| tree | 650c1b69cf798ae9ce1cafa0d812810f332cb968 /src | |
| parent | 0487663e7d9d7b542a66299dee64204f8c96689c (diff) | |
| download | rust-436d263aed2ef54cdcec84ecb9c99a71b487769e.tar.gz rust-436d263aed2ef54cdcec84ecb9c99a71b487769e.zip | |
Add a selectable trait.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/pipes.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index d16f0f3a330..618d49dbaf5 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -318,10 +318,22 @@ fn select2<A: send, B: send>( } } -fn selecti<T: send>(endpoints: &[&recv_packet<T>]) -> uint { +trait selectable { + pure fn header() -> *packet_header; +} + +fn selecti<T: selectable>(endpoints: &[T]) -> uint { wait_many(endpoints.map(|p| p.header())) } +fn select2i<A: selectable, B: selectable>(a: A, b: B) -> either<(), ()> { + alt wait_many([a.header(), b.header()]/_) { + 0 { left(()) } + 1 { right(()) } + _ { fail "wait returned unexpected index" } + } +} + #[doc = "Waits on a set of endpoints. Returns a message, its index, and a list of the remaining endpoints."] fn select<T: send>(+endpoints: ~[recv_packet<T>]) @@ -552,7 +564,7 @@ class port_set<T: send> { } } -impl private_methods/&<T: send> for pipes::port<T> { +impl<T: send> of selectable for pipes::port<T> { pure fn header() -> *pipes::packet_header unchecked { alt self.endp { some(endp) { |
