web_tools/iter/
html_collection.rs1pub struct IterableHtmlCollection<'a>(pub &'a web_sys::HtmlCollection);
3
4impl<'a> IntoIterator for IterableHtmlCollection<'a> {
5 type Item = web_sys::Element;
6 type IntoIter = HtmlCollectionIter<'a>;
7
8 fn into_iter(self) -> Self::IntoIter {
9 Self::IntoIter::new(self.0)
10 }
11}
12
13#[doc(hidden)]
14pub struct HtmlCollectionIter<'a> {
15 list: &'a web_sys::HtmlCollection,
16 index: u32,
17}
18
19impl<'a> HtmlCollectionIter<'a> {
20 pub fn new(list: &'a web_sys::HtmlCollection) -> Self {
21 Self { list, index: 0 }
22 }
23}
24
25impl<'a> Iterator for HtmlCollectionIter<'a> {
26 type Item = web_sys::Element;
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}