Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upIteratorExt: by_ref + take_while consumes one extra element #22802
Comments
This comment has been minimized.
This comment has been minimized.
|
So how would you expect
So when all items match the I suppose |
This comment has been minimized.
This comment has been minimized.
|
I think this is a somewhat general issue with fn main() {
let a = [1, 2, 3, 4, 5];
let mut it = a.iter();
{
let mut it2 = it.by_ref().peekable();
let _ = it2.peek();
}
for i in it {
println!("{}", i);
}
} |
This comment has been minimized.
This comment has been minimized.
|
Note: in the |
steveklabnik
added
the
A-libs
label
Feb 25, 2015
This comment has been minimized.
This comment has been minimized.
|
It's kind of a gotcha, but you're explicitly giving a mutable ref of your iterator to another object, so it's completely natural. What has been proposed before is a peeking version of take_while that can only be used on .peekable, that way you could use both take_while and still access the boundary iterator element afterwards. |
oli-obk
referenced this issue
Feb 27, 2015
Closed
get rid of unnecessary buffering during decode #65
This comment has been minimized.
This comment has been minimized.
|
This is documented behavior of a stable method, so I'm going to give it a close. It is a bit of a gotcha, but it also makes sense. |
oli-obk commentedFeb 25, 2015
take_whilealso consumes the first element that does NOT fullfill the condition.prints