@@ -13,7 +13,7 @@ use core::fmt;
1313use super :: { FDT_TAGSIZE , Fdt , FdtToken } ;
1414use crate :: error:: FdtParseError ;
1515use crate :: fdt:: property:: { FdtPropIter , FdtProperty } ;
16- use crate :: standard:: { DEFAULT_ADDRESS_CELLS , DEFAULT_SIZE_CELLS } ;
16+ use crate :: standard:: { DEFAULT_ADDRESS_CELLS , DEFAULT_SIZE_CELLS , DtNode } ;
1717
1818/// A node in a flattened device tree.
1919#[ derive( Debug , Clone , Copy ) ]
@@ -26,15 +26,16 @@ pub struct FdtNode<'a> {
2626 pub ( crate ) address_cells : u32 ,
2727}
2828
29- impl < ' a > FdtNode < ' a > {
30- pub ( crate ) fn new ( fdt : Fdt < ' a > , offset : usize ) -> Self {
31- Self {
32- fdt,
33- offset,
34- address_cells : DEFAULT_ADDRESS_CELLS ,
35- size_cells : DEFAULT_SIZE_CELLS ,
36- }
37- }
29+ impl < ' a > DtNode for FdtNode < ' a > {
30+ type Error = FdtParseError ;
31+ type StrRef < ' x >
32+ = & ' a str
33+ where
34+ Self : ' x ;
35+ type Property < ' x >
36+ = FdtProperty < ' x >
37+ where
38+ Self : ' x ;
3839
3940 /// Returns the name of this node.
4041 ///
@@ -49,36 +50,20 @@ impl<'a> FdtNode<'a> {
4950 /// # Examples
5051 ///
5152 /// ```
52- /// # use dtoolkit::fdt::Fdt;
53+ /// use dtoolkit::fdt::Fdt;
54+ /// use dtoolkit::standard::DtNode;
55+ ///
5356 /// # let dtb = include_bytes!("../../tests/dtb/test_children.dtb");
5457 /// let fdt = Fdt::new(dtb).unwrap();
5558 /// let root = fdt.root().unwrap();
5659 /// let child = root.child("child1").unwrap().unwrap();
5760 /// assert_eq!(child.name().unwrap(), "child1");
5861 /// ```
59- pub fn name ( & self ) -> Result < & ' a str , FdtParseError > {
62+ fn name ( & self ) -> Result < & ' a str , FdtParseError > {
6063 let name_offset = self . offset + FDT_TAGSIZE ;
6164 self . fdt . string_at_offset ( name_offset, None )
6265 }
6366
64- /// Returns the name of this node without the unit address, if any.
65- ///
66- /// # Errors
67- ///
68- /// Returns an
69- /// [`FdtErrorKind::InvalidOffset`](crate::error::FdtErrorKind::InvalidOffset)
70- /// if the name offset is invalid or an
71- /// [`FdtErrorKind::InvalidString`](crate::error::FdtErrorKind::InvalidString) if the string at the offset is not null-terminated
72- /// or contains invalid UTF-8.
73- pub fn name_without_address ( & self ) -> Result < & ' a str , FdtParseError > {
74- let name = self . name ( ) ?;
75- if let Some ( ( name, _) ) = name. split_once ( '@' ) {
76- Ok ( name)
77- } else {
78- Ok ( name)
79- }
80- }
81-
8267 /// Returns a property by its name.
8368 ///
8469 /// # Performance
@@ -99,7 +84,7 @@ impl<'a> FdtNode<'a> {
9984 /// # Errors
10085 ///
10186 /// Returns an error if a property's name or value cannot be read.
102- pub fn property ( & self , name : & str ) -> Result < Option < FdtProperty < ' a > > , FdtParseError > {
87+ fn property ( & self , name : & str ) -> Result < Option < FdtProperty < ' a > > , FdtParseError > {
10388 for property in self . properties ( ) {
10489 let property = property?;
10590 if property. name ( ) == name {
@@ -108,6 +93,17 @@ impl<'a> FdtNode<'a> {
10893 }
10994 Ok ( None )
11095 }
96+ }
97+
98+ impl < ' a > FdtNode < ' a > {
99+ pub ( crate ) fn new ( fdt : Fdt < ' a > , offset : usize ) -> Self {
100+ Self {
101+ fdt,
102+ offset,
103+ address_cells : DEFAULT_ADDRESS_CELLS ,
104+ size_cells : DEFAULT_SIZE_CELLS ,
105+ }
106+ }
111107
112108 /// Returns an iterator over the properties of this node.
113109 ///
@@ -159,7 +155,9 @@ impl<'a> FdtNode<'a> {
159155 /// # Examples
160156 ///
161157 /// ```
162- /// # use dtoolkit::fdt::Fdt;
158+ /// use dtoolkit::fdt::Fdt;
159+ /// use dtoolkit::standard::DtNode;
160+ ///
163161 /// # let dtb = include_bytes!("../../tests/dtb/test_children.dtb");
164162 /// let fdt = Fdt::new(dtb).unwrap();
165163 /// let root = fdt.root().unwrap();
@@ -168,7 +166,9 @@ impl<'a> FdtNode<'a> {
168166 /// ```
169167 ///
170168 /// ```
171- /// # use dtoolkit::fdt::Fdt;
169+ /// use dtoolkit::fdt::Fdt;
170+ /// use dtoolkit::standard::DtNode;
171+ ///
172172 /// # let dtb = include_bytes!("../../tests/dtb/test_children.dtb");
173173 /// let fdt = Fdt::new(dtb).unwrap();
174174 /// let root = fdt.root().unwrap();
@@ -197,7 +197,9 @@ impl<'a> FdtNode<'a> {
197197 /// # Examples
198198 ///
199199 /// ```
200- /// # use dtoolkit::fdt::Fdt;
200+ /// use dtoolkit::fdt::Fdt;
201+ /// use dtoolkit::standard::DtNode;
202+ ///
201203 /// # let dtb = include_bytes!("../../tests/dtb/test_children.dtb");
202204 /// let fdt = Fdt::new(dtb).unwrap();
203205 /// let root = fdt.root().unwrap();
0 commit comments