Minor codestyle improvements

This commit is contained in:
cyqsimon 2024-01-18 23:07:11 +08:00
parent e4d637a3d8
commit 9f36a7a284
No known key found for this signature in database
GPG Key ID: 1D8CE2F297390D65
1 changed files with 6 additions and 8 deletions

View File

@ -103,11 +103,11 @@ impl FromStr for Matcher {
} }
// guard variable syntax leftover fragments // guard variable syntax leftover fragments
if non_empty_segments.iter().any(|seg| { if non_empty_segments
seg.text() .iter()
.map(|t| t.contains(['$', '{', '}'])) .filter_map(Seg::text)
.unwrap_or(false) .any(|t| t.contains(['$', '{', '}']))
}) { {
bail!(r#"Invalid matcher: "{s}""#); bail!(r#"Invalid matcher: "{s}""#);
} }
@ -121,9 +121,7 @@ impl Matcher {
// if-let guard would be ideal here // if-let guard would be ideal here
// see: https://github.com/rust-lang/rust/issues/51114 // see: https://github.com/rust-lang/rust/issues/51114
1 if self.0[0].is_text() => { 1 if self.0[0].is_text() => {
let Some(s) = self.0[0].text() else { let s = self.0[0].text().unwrap();
unreachable!()
};
format!(r###"Lazy::new(|| Some(build_matcher_fixed(r#"{s}"#)))"###) format!(r###"Lazy::new(|| Some(build_matcher_fixed(r#"{s}"#)))"###)
} }
// parser logic ensures that this case can only happen when there are dynamic segments // parser logic ensures that this case can only happen when there are dynamic segments