summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-10-26 21:35:36 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-10-26 21:35:36 -0400
commit191a3e2d48e153492e1480166a8511d0563c957c (patch)
tree659f3490dd2b2c83238d558405dad8b427f301a4 /src
parent93933d808de27af1b45a120ce449b4cdfa2235c3 (diff)
downloadmon-191a3e2d48e153492e1480166a8511d0563c957c.tar.gz
take reference to regex struct in Regex parser
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 41a914c..3454e96 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1006,15 +1006,15 @@ pub mod str {
use super::*;
- struct Regex(regex::Regex);
+ struct Regex<'a>(&'a regex::Regex);
- impl<'a> Parser<&'a str> for Regex {
- type Output = &'a str;
+ impl<'src, 'regex> Parser<&'src str> for Regex<'regex> {
+ type Output = &'src str;
- fn run<OM: Mode, EM: Mode, Tracer: Trace<&'a str>>(
+ fn run<OM: Mode, EM: Mode, Tracer: Trace<&'src str>>(
&self,
- it: InputIter<&'a str>,
- ) -> ParserResult<&'a str, Self::Output, OM, EM> {
+ it: InputIter<&'src str>,
+ ) -> ParserResult<&'src str, Self::Output, OM, EM> {
match self.0.find(it.rest()) {
Some(m) => {
let output = OM::bind(|| it.rest().slice(m.range()));
@@ -1026,7 +1026,7 @@ pub mod str {
}
}
- pub fn regex<'a>(regexp: regex::Regex) -> impl Parser<&'a str, Output = &'a str> {
+ pub fn regex<'a>(regexp: &'a regex::Regex) -> impl Parser<&'a str, Output = &'a str> {
Regex(regexp)
}
}
@@ -1050,7 +1050,7 @@ mod test {
fn test_regex_parser() {
let it = InputIter::new("abc 123");
- match crate::str::regex(regex::Regex::new("[a-z]+").unwrap()).parse(it) {
+ match crate::str::regex(&regex::Regex::new("[a-z]+").unwrap()).parse(it) {
Ok((rest, output)) => {
assert_eq!(output, "abc");
assert_eq!(rest.rest(), " 123");