Le 12/08/2013 20:16, Corey Richardson a écrit :
On Mon, Aug 12, 2013 at 2:54 PM, Simon Sapin <simon.sa...@exyr.org> wrote:
fn main() {
let v = ~[1u, 7, 42, 0];
let mut it = v.move_iter().enumerate();
for_!((i, v) in it {
if v == 42 {
printfln!("Found it at %u", i);
break
}
} else {e
println("Not found");
})
}
v.move_iter().position(|a| a == 42)
One of Rust's strengths compared to Python is that we can implement
traits on adaptors and have generic methods.
That’s good, but this was only a trivial example to demonstrate the
macro. I’m not that interested about position() itself.
What triggered me starting this thread is this:
https://github.com/SimonSapin/servo-style/blob/c1b7e157b/media_queries.rs#L101
This is parsing a comma-separated list of Media Queries from an iterator
of tokens. Invalid comma-separated parts evaluate to false. So on a
syntax error, we consume the iterator until finding a comma, or the end
of the input. We want to do two different things in each case.
The `loop { match iter.next() { … }}` pattern works out okay in this
case, but a for-else loop would have been much nicer IMO.
--
Simon Sapin
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev