diff options
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; |