Skip to content

Commit 2cc24c2

Browse files
committed
feat(node): add compatibles method to retrieve compatible strings iterator
1 parent 35696e6 commit 2cc24c2

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

fdt-raw/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ name = "fdt-raw"
1111
readme = "README.md"
1212
homepage = "https://github.com/drivercraft/fdt-parser"
1313
repository = "https://github.com/drivercraft/fdt-parser"
14-
version = "0.1.2"
14+
version = "0.1.3"
1515

1616
[dependencies]
1717
heapless = "0.9"

fdt-raw/src/node/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ impl<'a> NodeBase<'a> {
119119
prop.data(),
120120
))
121121
}
122+
123+
pub fn compatibles(&self) -> impl Iterator<Item = &'a str> {
124+
self.find_property("compatible")
125+
.into_iter()
126+
.flat_map(|p| p.as_str_iter())
127+
}
122128
}
123129

124130
/// 写入缩进

fdt-raw/tests/node.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,15 @@ fn test_memory_in_fdt(raw: &[u8], name: &str) {
600600
);
601601
info!("[{}] Found {} memory node(s)", name, memory_nodes_found);
602602
}
603+
604+
605+
#[test]
606+
fn test_compatibles() {
607+
init_logging();
608+
let raw = fdt_qemu();
609+
let fdt = Fdt::from_bytes(&raw).unwrap();
610+
let node = fdt.find_by_path("/pl061@9030000").unwrap();
611+
for compatible in node.compatibles() {
612+
info!("compatible: {}", compatible);
613+
}
614+
}

0 commit comments

Comments
 (0)