Skip to content

Commit

Permalink
widen pattern type from &str to AsRef<str>
Browse files Browse the repository at this point in the history
  • Loading branch information
phenylshima committed Mar 25, 2024
1 parent 0170f59 commit 4b0d90d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions crates/jlabel-question/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ where
Self: Sized,
{
/// Parses question patterns in string, and if succeeds, returns the parsed question.
fn parse(patterns: &[&str]) -> Result<Self, ParseError>;
fn parse<S: AsRef<str>>(patterns: &[S]) -> Result<Self, ParseError>;

/// Checks if the full-context label matches the question.
///
Expand All @@ -193,12 +193,12 @@ pub enum AllQuestion {
}

impl QuestionMatcher for AllQuestion {
fn parse(patterns: &[&str]) -> Result<Self, ParseError> {
fn parse<S: AsRef<str>>(patterns: &[S]) -> Result<Self, ParseError> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/jlabel-question/src/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl RegexQuestion {
}

impl QuestionMatcher for RegexQuestion {
fn parse(patterns: &[&str]) -> Result<Self, ParseError> {
fn parse<S: AsRef<str>>(patterns: &[S]) -> Result<Self, ParseError> {
let regex = Regex::builder()
.build_from_hir(&Hir::alternation(
patterns.iter().map(Self::parse_wildcard).collect(),
Expand Down
2 changes: 1 addition & 1 deletion crates/jlabel-question/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 4b0d90d

Please sign in to comment.