fdt_rs/base/
node.rs

1#[cfg(doc)]
2use super::*;
3
4use crate::base::iters::{DevTreeIter, DevTreeNodePropIter};
5use crate::error::Result;
6
7/// A handle to a Device Tree Node within the device tree.
8#[derive(Clone)]
9pub struct DevTreeNode<'a, 'dt: 'a> {
10    pub(super) name: Result<&'dt str>,
11    pub(super) parse_iter: DevTreeIter<'a, 'dt>,
12}
13
14impl<'a, 'dt: 'a> PartialEq for DevTreeNode<'a, 'dt> {
15    fn eq(&self, other: &Self) -> bool {
16        self.parse_iter == other.parse_iter
17    }
18}
19
20impl<'a, 'dt: 'a> DevTreeNode<'a, 'dt> {
21    /// Returns the name of the `DevTreeNode` (including unit address tag)
22    #[inline]
23    pub fn name(&'a self) -> Result<&'dt str> {
24        self.name
25    }
26
27    /// Returns an iterator over this node's children [`DevTreeProp`]
28    #[must_use]
29    pub fn props(&self) -> DevTreeNodePropIter<'a, 'dt> {
30        DevTreeNodePropIter(self.parse_iter.clone())
31    }
32
33    /// Returns the next [`DevTreeNode`] object with the provided compatible device tree property
34    /// or `None` if none exists.
35    ///
36    /// # Example
37    ///
38    /// The following example iterates through all nodes with compatible value "virtio,mmio"
39    /// and prints each node's name.
40    ///
41    /// TODO
42    pub fn find_next_compatible_node(&self, string: &str) -> Result<Option<DevTreeNode<'a, 'dt>>> {
43        self.parse_iter.clone().next_compatible_node(string)
44    }
45}