morel/
algorithm.rs

1pub mod ahocorasick;
2
3use crate::types::Match;
4
5use self::ahocorasick::AhoCorasick;
6
7/// Any type which can be used to perform searches on a body of text.
8pub trait Algorithm: Clone + Send + Sync {
9    fn find(&self, text: &str, at: usize) -> Option<Match>;
10}
11
12/// Describes the algorithms that can be used to perform searches.
13pub enum Kind {
14    AhoCorasick,
15}
16
17/// A wrapper for Algorithm types that can be embedded in Finder and
18/// used to avoid trait objects.
19#[derive(Clone)]
20pub enum Wrapper {
21    AhoCorasick(AhoCorasick),
22}
23
24impl Algorithm for Wrapper {
25    fn find(&self, text: &str, at: usize) -> Option<Match> {
26        match self {
27            Wrapper::AhoCorasick(aho_corasick) => aho_corasick.find(text, at),
28        }
29    }
30}