1use crate::error::Error;
2use crate::{Fdt, FdtNode, FdtProperty};
3
4pub struct FdtNodeIter<'fdt> {
6 fdt: &'fdt Fdt,
7 next: Option<FdtNode<'fdt>>,
8}
9
10pub struct FdtPropertyIter<'fdt> {
12 fdt: &'fdt Fdt,
13 next: Option<FdtProperty<'fdt>>,
14}
15
16impl<'fdt> FdtNodeIter<'fdt> {
17 pub fn new(node: &FdtNode<'fdt>) -> Result<Self, Error> {
19 Ok(Self {
20 fdt: node.fdt,
21 next: node.fdt.first_subnode(node)?,
22 })
23 }
24}
25
26impl<'fdt> FdtPropertyIter<'fdt> {
27 pub fn new(node: &FdtNode<'fdt>) -> Result<Self, Error> {
29 Ok(Self {
30 fdt: node.fdt,
31 next: node.fdt.first_property(node)?,
32 })
33 }
34}
35
36impl<'fdt> Iterator for FdtNodeIter<'fdt> {
37 type Item = FdtNode<'fdt>;
38
39 fn next(&mut self) -> Option<Self::Item> {
40 if let Some(current) = self.next.take() {
41 self.next = self.fdt.next_subnode(¤t).unwrap();
42 Some(current)
43 } else {
44 None
45 }
46 }
47}
48
49impl<'fdt> Iterator for FdtPropertyIter<'fdt> {
50 type Item = FdtProperty<'fdt>;
51
52 fn next(&mut self) -> Option<Self::Item> {
53 if let Some(current) = self.next.take() {
54 self.next = self.fdt.next_property(¤t).unwrap();
55 Some(current)
56 } else {
57 None
58 }
59 }
60}