diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-05-05 19:28:57 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-05-05 19:28:57 +0300 |
commit | 6498b2eecb21ad87069be8f501f35374745106d9 (patch) | |
tree | 18af0fcdb186609452825adb3155badcd4aaa013 /src/bindings.rs | |
parent | 12059fcb1ce8237e5587773043cd442e036531c2 (diff) | |
download | subplot-6498b2eecb21ad87069be8f501f35374745106d9.tar.gz |
refactor: drop the subplot::Result type alias
Replace subplot::Result<T> with Result<T, SubplotError>. I find this
now to be clearer, as I don't need to remind myself which Result is
being used where. This should not be a breaking change.
Sponsored-by: author
Diffstat (limited to 'src/bindings.rs')
-rw-r--r-- | src/bindings.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/bindings.rs b/src/bindings.rs index 0837553..5c98297 100644 --- a/src/bindings.rs +++ b/src/bindings.rs @@ -3,7 +3,7 @@ use super::MatchedSteps; use super::PartialStep; use super::ScenarioStep; use super::StepKind; -use crate::{resource, Result, SubplotError}; +use crate::{resource, SubplotError}; use serde::{Deserialize, Serialize}; use serde_aux::prelude::*; @@ -54,7 +54,7 @@ pub enum CaptureType { impl FromStr for CaptureType { type Err = SubplotError; - fn from_str(value: &str) -> Result<Self> { + fn from_str(value: &str) -> Result<Self, SubplotError> { match value.to_ascii_lowercase().as_str() { "word" => Ok(Self::Word), "text" => Ok(Self::Text), @@ -168,7 +168,7 @@ impl Binding { pattern: &str, case_sensitive: bool, mut types: HashMap<String, CaptureType>, - ) -> Result<Binding> { + ) -> Result<Binding, SubplotError> { let regex = RegexBuilder::new(&format!("^{}$", pattern)) .case_insensitive(!case_sensitive) .build()?; @@ -462,7 +462,7 @@ impl Bindings { } /// Add bindings from a YAML string - pub fn add_from_yaml(&mut self, yaml: &str) -> Result<()> { + pub fn add_from_yaml(&mut self, yaml: &str) -> Result<(), SubplotError> { let bindings: Vec<ParsedBindingWrapper> = serde_yaml::from_str(yaml)?; for wrapper in bindings { self.add(from_hashmap(&wrapper.binding)?); @@ -477,7 +477,7 @@ impl Bindings { /// Find the binding matching a given scenario step, if there is /// exactly one. - pub fn find(&self, template: &str, step: &ScenarioStep) -> Result<MatchedStep> { + pub fn find(&self, template: &str, step: &ScenarioStep) -> Result<MatchedStep, SubplotError> { let mut matches: Vec<MatchedStep> = self .bindings() .iter() @@ -499,7 +499,11 @@ impl Bindings { } /// Add bindings from a file. - pub fn add_from_file<P>(&mut self, filename: P, template: Option<&str>) -> Result<()> + pub fn add_from_file<P>( + &mut self, + filename: P, + template: Option<&str>, + ) -> Result<(), SubplotError> where P: AsRef<Path> + Debug, { @@ -522,7 +526,7 @@ impl Bindings { } } -fn from_hashmap(parsed: &ParsedBinding) -> Result<Binding> { +fn from_hashmap(parsed: &ParsedBinding) -> Result<Binding, SubplotError> { let given: i32 = parsed.given.is_some().into(); let when: i32 = parsed.when.is_some().into(); let then: i32 = parsed.then.is_some().into(); @@ -796,7 +800,7 @@ fn regex_from_simple_pattern( pattern: &str, explicit_plain: bool, types: &mut HashMap<String, CaptureType>, -) -> Result<String> { +) -> Result<String, SubplotError> { let pat = Regex::new(r"\{[^\s\{\}]+\}").unwrap(); let mut r = String::new(); let mut end = 0; |