]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #10688 : bjz/rust/recv_iter, r=brson
authorbors <bors@rust-lang.org>
Wed, 27 Nov 2013 09:52:10 +0000 (01:52 -0800)
committerbors <bors@rust-lang.org>
Wed, 27 Nov 2013 09:52:10 +0000 (01:52 -0800)
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 `recv_iter` 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 for further `recv`ing and `peek`ing with no borrow errors, which is quite nice.


Trivial merge