Skip to content

Commit 431a168

Browse files
committed
style: adjust the code according to clippy
1 parent 3254731 commit 431a168

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

src/cli.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ impl Command {
108108
out_path,
109109
*input_format,
110110
*output_format,
111-
*expand,
112-
*expand_properties,
113-
*ignore_enums,
111+
convert_cli::ParserConfig {
112+
expand: *expand,
113+
expand_properties: *expand_properties,
114+
ignore_enums: *ignore_enums,
115+
},
114116
format_config.as_ref().map(|p| p.as_path()),
115117
)?,
116118
}

src/convert/convert_cli.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl FromStr for InputFormat {
1818
"svd" | "SVD" | "xml" | "XML" => Ok(Self::Xml),
1919
"yml" | "yaml" | "YAML" => Ok(Self::Yaml),
2020
"json" | "JSON" => Ok(Self::Json),
21-
_ => return Err(anyhow!("Unknown input file format")),
21+
_ => Err(anyhow!("Unknown input file format")),
2222
}
2323
}
2424
}
@@ -38,7 +38,7 @@ impl FromStr for OutputFormat {
3838
"svd" | "SVD" | "xml" | "XML" => Ok(Self::Xml),
3939
"yml" | "yaml" | "YAML" => Ok(Self::Yaml),
4040
"json" | "JSON" => Ok(Self::Json),
41-
_ => return Err(anyhow!("Unknown output file format")),
41+
_ => Err(anyhow!("Unknown output file format")),
4242
}
4343
}
4444
}
@@ -61,14 +61,18 @@ impl FromStr for ConfigFormat {
6161
}
6262
}
6363

64+
pub struct ParserConfig {
65+
pub expand: bool,
66+
pub expand_properties: bool,
67+
pub ignore_enums: bool,
68+
}
69+
6470
pub fn convert(
6571
in_path: &Path,
6672
out_path: &Path,
6773
input_format: Option<InputFormat>,
6874
output_format: Option<OutputFormat>,
69-
expand: bool,
70-
expand_properties: bool,
71-
ignore_enums: bool,
75+
parser_config: ParserConfig,
7276
format_config: Option<&Path>,
7377
) -> Result<()> {
7478
let input_format = match input_format {
@@ -92,15 +96,15 @@ pub fn convert(
9296
let mut device = match input_format {
9397
InputFormat::Xml => svd_parser::parse_with_config(
9498
&input,
95-
&svd_parser::Config::default().ignore_enums(ignore_enums),
99+
&svd_parser::Config::default().ignore_enums(parser_config.ignore_enums),
96100
)?,
97101
InputFormat::Yaml => serde_yaml::from_str(&input)?,
98102
InputFormat::Json => serde_json::from_str(&input)?,
99103
};
100-
if expand_properties {
104+
if parser_config.expand_properties {
101105
svd_parser::expand_properties(&mut device);
102106
}
103-
let device = if expand {
107+
let device = if parser_config.expand {
104108
svd_parser::expand(&device)?
105109
} else {
106110
device

src/patch/device.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,9 @@ pub struct PerIter<'a, 'b> {
1919
impl<'a, 'b> Iterator for PerIter<'a, 'b> {
2020
type Item = &'a mut Peripheral;
2121
fn next(&mut self) -> Option<Self::Item> {
22-
for next in self.it.by_ref() {
23-
if matchname(&next.name, self.spec)
24-
&& !(self.check_derived && next.derived_from.is_some())
25-
{
26-
return Some(next);
27-
}
28-
}
29-
None
22+
self.it.by_ref().find(|next| {
23+
matchname(&next.name, self.spec) && !(self.check_derived && next.derived_from.is_some())
24+
})
3025
}
3126
}
3227

src/patch/iterators.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ where
1818
{
1919
type Item = I::Item;
2020
fn next(&mut self) -> Option<Self::Item> {
21-
for next in self.it.by_ref() {
22-
if matchname(next.name(), self.spec) {
23-
return Some(next);
24-
}
25-
}
26-
None
21+
self.it
22+
.by_ref()
23+
.find(|next| matchname(next.name(), self.spec))
2724
}
2825
}
2926

@@ -60,7 +57,7 @@ where
6057
}
6158
}
6259

63-
impl<'a, I> Iterator for OptIter<I>
60+
impl<I> Iterator for OptIter<I>
6461
where
6562
I: Iterator,
6663
{

0 commit comments

Comments
 (0)