mozilla/rust — pull request #10688 by bjz (2013-11-27 05:17:16+00:00)
Title: Add an iterator for receiving messages from GenericPorts

I've noticed I use this pattern quite a bit:

~~~rust
do spawn {
loop {
match port.try_recv() {
Some(x) => ...,
None => ...,
}
}
}
~~~

The `RecvIterator`, returned from a default method on the `GenericPort` trait, allows you to reduce this down to:

~~~rust
do spawn {
for x in port.recv_iter() {
...
}
}
~~~

As demonstrated in the tests, you can also access the port from within the `for` block with no borrow errors, which is quite nice.

r? @brson