From 4b0d90d295a24dc0b94892cbb7e3f1fbd30137db Mon Sep 17 00:00:00 2001 From: femshima <49227365+femshima@users.noreply.github.com> Date: Mon, 25 Mar 2024 15:26:22 +0900 Subject: [PATCH] widen pattern type from &str to AsRef --- crates/jlabel-question/src/lib.rs | 6 +++--- crates/jlabel-question/src/regex.rs | 2 +- crates/jlabel-question/src/tests.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/jlabel-question/src/lib.rs b/crates/jlabel-question/src/lib.rs index f7e2964..92d370d 100644 --- a/crates/jlabel-question/src/lib.rs +++ b/crates/jlabel-question/src/lib.rs @@ -166,7 +166,7 @@ where Self: Sized, { /// Parses question patterns in string, and if succeeds, returns the parsed question. - fn parse(patterns: &[&str]) -> Result; + fn parse>(patterns: &[S]) -> Result; /// Checks if the full-context label matches the question. /// @@ -193,12 +193,12 @@ pub enum AllQuestion { } impl QuestionMatcher for AllQuestion { - fn parse(patterns: &[&str]) -> Result { + fn parse>(patterns: &[S]) -> Result { let mut position = None; let mut ranges = Vec::with_capacity(patterns.len()); for pattern in patterns { - let (pos, range) = estimate_position(pattern)?; + let (pos, range) = estimate_position(pattern.as_ref())?; if let Some(position) = position { if pos != position { diff --git a/crates/jlabel-question/src/regex.rs b/crates/jlabel-question/src/regex.rs index b2c0d0a..29cfb0c 100644 --- a/crates/jlabel-question/src/regex.rs +++ b/crates/jlabel-question/src/regex.rs @@ -36,7 +36,7 @@ impl RegexQuestion { } impl QuestionMatcher for RegexQuestion { - fn parse(patterns: &[&str]) -> Result { + fn parse>(patterns: &[S]) -> Result { let regex = Regex::builder() .build_from_hir(&Hir::alternation( patterns.iter().map(Self::parse_wildcard).collect(), diff --git a/crates/jlabel-question/src/tests.rs b/crates/jlabel-question/src/tests.rs index 1dd382c..d8fc60a 100644 --- a/crates/jlabel-question/src/tests.rs +++ b/crates/jlabel-question/src/tests.rs @@ -69,7 +69,7 @@ fn parse_question_err() { use ParseError::*; use PositionError::*; - assert_eq!(AllQuestion::parse(&[]), Err(Empty)); + assert_eq!(AllQuestion::parse::<&str>(&[]), Err(Empty)); assert_eq!( AllQuestion::parse(&["*/A:*"]), Err(InvalidPosition(EmptyRange))