web_tools/iter/
node_list.rs

1/// Allow iterating over a [`NodeList`].
2pub struct IterableNodeList<'a>(pub &'a web_sys::NodeList);
3
4impl<'a> IntoIterator for IterableNodeList<'a> {
5    type Item = web_sys::Node;
6    type IntoIter = NodeListIter<'a>;
7
8    fn into_iter(self) -> Self::IntoIter {
9        Self::IntoIter::new(self.0)
10    }
11}
12
13#[doc(hidden)]
14pub struct NodeListIter<'a> {
15    list: &'a web_sys::NodeList,
16    index: u32,
17}
18
19impl<'a> NodeListIter<'a> {
20    pub fn new(list: &'a web_sys::NodeList) -> Self {
21        Self { list, index: 0 }
22    }
23}
24
25impl<'a> Iterator for NodeListIter<'a> {
26    type Item = web_sys::Node;
27
28    fn next(&mut self) -> Option<Self::Item> {
29        let next = self.list.item(self.index);
30        self.index += 1;
31        next
32    }
33}