1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::api::Match;
use crate::insn::CompiledRegex;
use crate::position::PositionType;
pub trait MatchProducer: std::fmt::Debug {
type Position: PositionType;
fn initial_position(&self, offset: usize) -> Option<Self::Position>;
fn next_match(
&mut self,
pos: Self::Position,
next_start: &mut Option<Self::Position>,
) -> Option<Match>;
}
pub trait Executor<'r, 't>: MatchProducer {
type AsAscii: Executor<'r, 't>;
fn new(re: &'r CompiledRegex, text: &'t str) -> Self;
}
#[derive(Debug)]
pub struct Matches<Producer: MatchProducer> {
mp: Producer,
position: Option<Producer::Position>,
}
impl<Producer: MatchProducer> Matches<Producer> {
pub fn new(mp: Producer, start: usize) -> Self {
let position = mp.initial_position(start);
Matches { mp, position }
}
}
impl<Producer: MatchProducer> Iterator for Matches<Producer> {
type Item = Match;
fn next(&mut self) -> Option<Self::Item> {
let pos = self.position?;
self.mp.next_match(pos, &mut self.position)
}
}