Skip to content

Commit 5208240

Browse files
committed
Auto merge of #30 - brandonedens:match_periph_name_exactly, r=japaric
Match peripheral name exactly Match peripheral name exactly to prevent specification of peripheral such as tim1 accidentally returning peripheral details for tim15 for instance.
2 parents 1724d0d + a5feced commit 5208240

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)