summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2021-05-20 00:25:42 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2021-05-20 00:25:42 +0100
commit6bf39fdb44dcbcd29c13b71aaa22c01b4741ec51 (patch)
treed9555b2e58ba198fcd9f3128e9681ca0d5457b31 /src
parente762e23a9ac7b36c6abfc8c45d1b48407263007f (diff)
downloadsubplot-6bf39fdb44dcbcd29c13b71aaa22c01b4741ec51.tar.gz
chore: Fix a bunch of clippy lints
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src')
-rw-r--r--src/bindings.rs74
-rw-r--r--src/metadata.rs17
-rw-r--r--src/scenarios.rs5
-rw-r--r--src/templatespec.rs10
4 files changed, 39 insertions, 67 deletions
diff --git a/src/bindings.rs b/src/bindings.rs
index 99fd6cf..d17460f 100644
--- a/src/bindings.rs
+++ b/src/bindings.rs
@@ -8,7 +8,6 @@ use serde::{Deserialize, Serialize};
use serde_aux::prelude::*;
use std::collections::HashMap;
-use std::convert::identity;
use std::path::Path;
use std::str::FromStr;
@@ -119,7 +118,7 @@ impl Binding {
// For every named capture, ensure we have a known type for it.
// If the type is missing from the map, we default to `text` which is
// the .* pattern
- for capture in regex.capture_names().filter_map(identity) {
+ for capture in regex.capture_names().flatten() {
types.entry(capture.into()).or_insert(CaptureType::Text);
}
@@ -150,10 +149,7 @@ impl Binding {
/// Return name of function that implements cleanup.
pub fn cleanup(&self) -> Option<&str> {
- match self.cleanup {
- None => None,
- Some(ref s) => Some(&s),
- }
+ self.cleanup.as_deref()
}
/// Return the compiled regular expression for the pattern of the
@@ -183,47 +179,43 @@ impl Binding {
// Otherwise, return captures as PartialStep::Text, and the
// surrounding text as PartialStep::UnmatchedText.
let mut prev_end = 0;
- for cap in caps.iter().skip(1) {
- if let Some(cap) = cap {
- if cap.start() > prev_end {
- let part = PartialStep::uncaptured(&step_text[prev_end..cap.start()]);
- m.append_part(part);
- }
+ for cap in caps.iter().skip(1).flatten() {
+ if cap.start() > prev_end {
+ let part = PartialStep::uncaptured(&step_text[prev_end..cap.start()]);
+ m.append_part(part);
+ }
- // Find name for capture.
- let mut capname: Option<&str> = None;
- for name in self.regex.capture_names() {
- if let Some(name) = name {
- if let Some(mm) = caps.name(name) {
- if mm.start() == cap.start() && mm.end() == cap.end() {
- capname = Some(name);
- }
- }
+ // Find name for capture.
+ let mut capname: Option<&str> = None;
+ for name in self.regex.capture_names().flatten() {
+ if let Some(mm) = caps.name(name) {
+ if mm.start() == cap.start() && mm.end() == cap.end() {
+ capname = Some(name);
}
}
+ }
- let part = match capname {
- None => PartialStep::uncaptured(&step_text[prev_end..cap.start()]),
- Some(name) => {
- // Before continuing, verify that the capture matches the
- // pattern for this capture
- let cap = cap.as_str();
- // These unwraps are safe because we ensured the map is complete
- // in the constructor, and that all the types are known.
- let ty = self.types.get(name).unwrap();
- let rx = &KIND_PATTERNS.get(ty).unwrap();
- if !rx.is_match(cap) {
- // This capture doesn't match the kind so it's not
- // valid for this binding.
- return None;
- }
- PartialStep::text(name, cap)
+ let part = match capname {
+ None => PartialStep::uncaptured(&step_text[prev_end..cap.start()]),
+ Some(name) => {
+ // Before continuing, verify that the capture matches the
+ // pattern for this capture
+ let cap = cap.as_str();
+ // These unwraps are safe because we ensured the map is complete
+ // in the constructor, and that all the types are known.
+ let ty = self.types.get(name).unwrap();
+ let rx = &KIND_PATTERNS.get(ty).unwrap();
+ if !rx.is_match(cap) {
+ // This capture doesn't match the kind so it's not
+ // valid for this binding.
+ return None;
}
- };
+ PartialStep::text(name, cap)
+ }
+ };
- m.append_part(part);
- prev_end = cap.end();
- }
+ m.append_part(part);
+ prev_end = cap.end();
}
// There might be unmatched text at the end.
diff --git a/src/metadata.rs b/src/metadata.rs
index 3f4916a..8406e38 100644
--- a/src/metadata.rs
+++ b/src/metadata.rs
@@ -63,11 +63,7 @@ impl Metadata {
/// Return date of document, if any.
pub fn date(&self) -> Option<&str> {
- if let Some(date) = &self.date {
- Some(&date)
- } else {
- None
- }
+ self.date.as_deref()
}
/// Return filename where bindings are specified.
@@ -85,10 +81,7 @@ impl Metadata {
/// Return the name of the code template, if specified.
pub fn template_name(&self) -> Option<&str> {
- match &self.template {
- Some(x) => Some(&x),
- None => None,
- }
+ self.template.as_deref()
}
/// Return the bindings.
@@ -118,11 +111,7 @@ fn get_title(map: &Mapp) -> String {
}
fn get_date(map: &Mapp) -> Option<String> {
- if let Some(s) = get_string(map, "date") {
- Some(s)
- } else {
- None
- }
+ get_string(map, "date")
}
fn get_bindings_filenames<P>(basedir: P, map: &Mapp) -> Vec<PathBuf>
diff --git a/src/scenarios.rs b/src/scenarios.rs
index bb1e3df..9285f1b 100644
--- a/src/scenarios.rs
+++ b/src/scenarios.rs
@@ -38,10 +38,7 @@ impl Scenario {
/// Return name of scenario.
pub fn name(&self) -> Option<&str> {
- match self.name {
- None => None,
- Some(ref name) => Some(&name),
- }
+ self.name.as_deref()
}
/// Does the scenario have steps?
diff --git a/src/templatespec.rs b/src/templatespec.rs
index d2389d8..e997aad 100644
--- a/src/templatespec.rs
+++ b/src/templatespec.rs
@@ -35,10 +35,7 @@ impl TemplateSpec {
TemplateSpec {
template: basedir.to_path_buf().join(template),
helpers,
- run: match run {
- Some(x) => Some(x.to_string()),
- None => None,
- },
+ run: run.map(str::to_string),
}
}
@@ -76,10 +73,7 @@ impl TemplateSpec {
///
/// The name of the test program gets appended.
pub fn run(&self) -> Option<&str> {
- match &self.run {
- Some(run) => Some(&run),
- None => None,
- }
+ self.run.as_deref()
}
}