Skip to content

Commit a5feced

Browse files
committed
Match peripheral name exactly to prevent specification of peripheral
such as tim1 accidentally returning peripheral details for tim15 for instance otherwise fail over to contains match ordered by SVD peripheral listing.
1 parent 45301d5 commit a5feced

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ fn main() {
4141
}
4242
}
4343
Some(pattern) => {
44-
for peripheral in &d.peripherals {
45-
if peripheral.name.to_ascii_lowercase().contains(&pattern) {
46-
println!("{}",
47-
svd2rust::gen_peripheral(peripheral, &d.defaults)
48-
.iter()
49-
.map(|i| i.to_string())
50-
.collect::<Vec<_>>()
51-
.join("\n\n"));
44+
if let Some(peripheral) = d.peripherals
45+
.iter()
46+
.find(|x| x.name.to_ascii_lowercase() == pattern)
47+
.or(d.peripherals.iter().find(|x| x.name.to_ascii_lowercase().contains(&pattern))) {
48+
println!("{}",
49+
svd2rust::gen_peripheral(peripheral, &d.defaults)
50+
.iter()
51+
.map(|i| i.to_string())
52+
.collect::<Vec<_>>()
53+
.join("\n\n"));
5254

53-
break;
54-
}
5555
}
5656
}
5757
}

0 commit comments

Comments
 (0)