]> git.lizzy.rs Git - rust.git/commit
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)
commit17af6f7d0c92ee66df6b96d088e999db378ce125
tree65f40f7d033969cd37a071f5242685f4305a684e
parentfaf4c939fb6c55f0b9d19b1292fa4601169b3c17
parent31da6b76986f337483a971884113a043c835102b
auto merge of #10688 : bjz/rust/recv_iter, r=brson

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.