Skip to content

Commit

Permalink
fix: untrue lifetime parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnarus-G committed May 6, 2023
1 parent b716639 commit 1d2f145
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
14 changes: 7 additions & 7 deletions mrp/src/captures.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#[derive(Debug, PartialEq)]
struct Capture<'i> {
name: &'i str,
value: &'i str,
struct Capture<'source, 'input> {
name: &'source str,
value: &'input str,
}

#[derive(Debug, PartialEq)]
pub struct Captures<'i> {
inner: Vec<Capture<'i>>,
pub struct Captures<'source, 'input> {
inner: Vec<Capture<'source, 'input>>,
}

impl<'i> Captures<'i> {
impl<'source, 'input> Captures<'source, 'input> {
pub fn new() -> Self {
Self { inner: vec![] }
}
pub fn put(&mut self, name: &'i str, value: &'i str) {
pub fn put(&mut self, name: &'source str, value: &'input str) {
self.inner.push(Capture { name, value });
}
pub fn get(&self, name: &str) -> Option<&str> {
Expand Down
18 changes: 7 additions & 11 deletions mrp/src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ use crate::{
};

pub struct Match<'input> {
text: &'input str,
input: &'input str,
pub start: usize,
pub end: usize,
}

impl<'input> Match<'input> {
pub fn as_str(&self) -> &str {
&self.text[self.start..self.end]
&self.input[self.start..self.end]
}
}

impl<'source> MatchExpression<'source> {
pub fn find_at_capturing<'input: 'source>(
pub fn find_at_capturing<'input>(
&self,
input: &'input str,
start: usize,
) -> (Option<Match<'input>>, Captures<'source>) {
) -> (Option<Match<'input>>, Captures<'source, 'input>) {
let mut curr_position = start;
let mut legit_start = start;
let mut state = 0;
Expand Down Expand Up @@ -115,7 +115,7 @@ impl<'source> MatchExpression<'source> {
if state == self.expressions.len() {
return (
Some(Match {
text: input,
input,
start: legit_start,
end: curr_position,
}),
Expand All @@ -127,11 +127,7 @@ impl<'source> MatchExpression<'source> {
}

/// Find the leftmost-first match in the input starting at the given position
pub fn find_at<'input: 'source>(
&self,
input: &'input str,
start: usize,
) -> Option<Match<'input>> {
pub fn find_at<'input>(&self, input: &'input str, start: usize) -> Option<Match<'input>> {
self.find_at_capturing(input, start).0
}

Expand All @@ -157,7 +153,7 @@ impl<'input, 'source> Matches<'input, 'source> {
}
}

impl<'input: 'source, 'source> Iterator for Matches<'input, 'source> {
impl<'input, 'source> Iterator for Matches<'input, 'source> {
type Item = Match<'input>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down

0 comments on commit 1d2f145

Please sign in to comment.