use crate::api::Match;
use crate::insn::CompiledRegex;
pub trait MatchProducer: std::fmt::Debug {
fn next_match(&mut self, pos: usize, next_start: &mut Option<usize>) -> 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,
offset: Option<usize>,
}
impl<Producer: MatchProducer> Matches<Producer> {
pub fn new(mp: Producer, start: usize) -> Self {
Matches {
mp,
offset: Some(start),
}
}
}
impl<Producer: MatchProducer> Iterator for Matches<Producer> {
type Item = Match;
fn next(&mut self) -> Option<Self::Item> {
let start = self.offset?;
self.mp.next_match(start, &mut self.offset)
}
}