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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
pub mod relation;
pub mod state;
pub use self::state::ItemState;
use std::{slice, iter};
use ::syntex_syntax::{ptr, ast};
use ::itertools::Itertools;
#[derive(Debug, Clone)]
pub struct Item <'a> {
it: iter::Peekable<slice::Iter<'a, ptr::P<ast::Item>>>,
}
impl <'a>From<iter::Peekable<slice::Iter<'a, ptr::P<ast::Item>>>> for Item<'a> {
fn from(iter: iter::Peekable<slice::Iter<'a, ptr::P<ast::Item>>>) -> Item {
Item {
it: iter,
}
}
}
impl <'a>Iterator for Item<'a> {
type Item = ItemState<'a>;
fn next(&mut self) -> Option<ItemState<'a>> {
self.it.next().and_then(|item| {
let mut list: Vec<&'a ptr::P<ast::Item>> = vec!(item);
list.extend(self.it.peeking_take_while(|ref item| {
if let ast::ItemKind::Impl(_, _, _, _, _, _) = item.node {
true
} else {
false
}
})
.collect::<Vec<&'a ptr::P<ast::Item>>>());
Some(ItemState::from(list))
})
}
}