Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widen pattern type from &str to S: AsRef<str> #31

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading