diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-05-20 00:25:42 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-05-20 00:25:42 +0100 |
commit | 6bf39fdb44dcbcd29c13b71aaa22c01b4741ec51 (patch) | |
tree | d9555b2e58ba198fcd9f3128e9681ca0d5457b31 /src/bindings.rs | |
parent | e762e23a9ac7b36c6abfc8c45d1b48407263007f (diff) | |
download | subplot-6bf39fdb44dcbcd29c13b71aaa22c01b4741ec51.tar.gz |
chore: Fix a bunch of clippy lints
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src/bindings.rs')
-rw-r--r-- | src/bindings.rs | 74 |
1 files changed, 33 insertions, 41 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. |