Skip to content

Commit bc60d84

Browse files
committed
core::pipes: Just reordering declarations
1 parent 0617d58 commit bc60d84

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

src/libcore/comm.rs

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,6 @@ pub trait Peekable<T> {
5656
fn peek(&self) -> bool;
5757
}
5858

59-
/// Returns the index of an endpoint that is ready to receive.
60-
pub fn selecti<T: Selectable>(endpoints: &[T]) -> uint {
61-
wait_many(endpoints)
62-
}
63-
64-
/// Returns 0 or 1 depending on which endpoint is ready to receive
65-
pub fn select2i<A: Selectable, B: Selectable>(a: &A, b: &B) ->
66-
Either<(), ()> {
67-
match wait_many([a.header(), b.header()]) {
68-
0 => Left(()),
69-
1 => Right(()),
70-
_ => fail!(~"wait returned unexpected index")
71-
}
72-
}
7359

7460
// Streams - Make pipes a little easier in general.
7561

@@ -322,38 +308,6 @@ pub fn SharedChan<T:Owned>(c: Chan<T>) -> SharedChan<T> {
322308
unstable::exclusive(c)
323309
}
324310
325-
/// Receive a message from one of two endpoints.
326-
pub trait Select2<T: Owned, U: Owned> {
327-
/// Receive a message or return `None` if a connection closes.
328-
fn try_select(&self) -> Either<Option<T>, Option<U>>;
329-
/// Receive a message or fail if a connection closes.
330-
fn select(&self) -> Either<T, U>;
331-
}
332-
333-
impl<T: Owned, U: Owned,
334-
Left: Selectable + GenericPort<T>,
335-
Right: Selectable + GenericPort<U>>
336-
Select2<T, U> for (Left, Right) {
337-
338-
fn select(&self) -> Either<T, U> {
339-
match *self {
340-
(ref lp, ref rp) => match select2i(lp, rp) {
341-
Left(()) => Left (lp.recv()),
342-
Right(()) => Right(rp.recv())
343-
}
344-
}
345-
}
346-
347-
fn try_select(&self) -> Either<Option<T>, Option<U>> {
348-
match *self {
349-
(ref lp, ref rp) => match select2i(lp, rp) {
350-
Left(()) => Left (lp.try_recv()),
351-
Right(()) => Right(rp.try_recv())
352-
}
353-
}
354-
}
355-
}
356-
357311
/*proto! oneshot (
358312
Oneshot:send<T:Owned> {
359313
send(T) -> !
@@ -486,6 +440,55 @@ pub fn try_send_one<T: Owned>(chan: ChanOne<T>, data: T)
486440
oneshot::client::try_send(chan, data).is_some()
487441
}
488442
443+
444+
445+
/// Returns the index of an endpoint that is ready to receive.
446+
pub fn selecti<T: Selectable>(endpoints: &[T]) -> uint {
447+
wait_many(endpoints)
448+
}
449+
450+
/// Returns 0 or 1 depending on which endpoint is ready to receive
451+
pub fn select2i<A: Selectable, B: Selectable>(a: &A, b: &B) ->
452+
Either<(), ()> {
453+
match wait_many([a.header(), b.header()]) {
454+
0 => Left(()),
455+
1 => Right(()),
456+
_ => fail!(~"wait returned unexpected index")
457+
}
458+
}
459+
460+
/// Receive a message from one of two endpoints.
461+
pub trait Select2<T: Owned, U: Owned> {
462+
/// Receive a message or return `None` if a connection closes.
463+
fn try_select(&self) -> Either<Option<T>, Option<U>>;
464+
/// Receive a message or fail if a connection closes.
465+
fn select(&self) -> Either<T, U>;
466+
}
467+
468+
impl<T: Owned, U: Owned,
469+
Left: Selectable + GenericPort<T>,
470+
Right: Selectable + GenericPort<U>>
471+
Select2<T, U> for (Left, Right) {
472+
473+
fn select(&self) -> Either<T, U> {
474+
match *self {
475+
(ref lp, ref rp) => match select2i(lp, rp) {
476+
Left(()) => Left (lp.recv()),
477+
Right(()) => Right(rp.recv())
478+
}
479+
}
480+
}
481+
482+
fn try_select(&self) -> Either<Option<T>, Option<U>> {
483+
match *self {
484+
(ref lp, ref rp) => match select2i(lp, rp) {
485+
Left(()) => Left (lp.try_recv()),
486+
Right(()) => Right(rp.try_recv())
487+
}
488+
}
489+
}
490+
}
491+
489492
#[cfg(test)]
490493
mod test {
491494
use either::Right;

0 commit comments

Comments
 (0)