/
iter.rs
31 lines (28 loc) · 883 Bytes
/
iter.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! A replacement for Iterator
#![macro_escape]
/// Like `Iterator`, but it allows you to store temporary data in the
/// iterator itself, and return temporary references from `next`.
///
/// Massive thanks to Sharp for figuring out how to do this.
pub trait StreamingIterator<'a, T> {
/// Return either the next item in the sequence, or `None` if all items
/// have been consumed.
fn next(&'a mut self) -> Option<T>;
}
/// Similar to `for`, but doesn't enforce any trait restrictions on the
/// iterator.
#[macro_export]
macro_rules! streaming_for {
($var:pat in $expr:expr, $b:stmt) => {
{
// Only evaluate once!
let ref mut iter = &mut $expr;
loop {
match iter.next() {
None => { break; }
Some($var) => { $b }
}
}
}
};
}