string_sections/
section_finder.rs1use crate::{LineSpan, SectionSpan};
2
3pub trait SectionFinder {
4 fn is_start(&self, line: &LineSpan) -> bool;
5 fn is_end(&self, section: &SectionSpan) -> bool;
6}
7
8pub struct SectionFnFinder<S, E>
9where
10 S: Fn(&LineSpan) -> bool,
11 E: Fn(&SectionSpan) -> bool,
12{
13 start: S,
14 end: E,
15}
16
17impl<S, E> SectionFinder for SectionFnFinder<S, E>
18where
19 S: Fn(&LineSpan) -> bool,
20 E: Fn(&SectionSpan) -> bool,
21{
22 fn is_start(&self, line: &LineSpan) -> bool {
23 (self.start)(line)
24 }
25
26 fn is_end(&self, section: &SectionSpan) -> bool {
27 (self.end)(section)
28 }
29}
30impl<S, E> SectionFnFinder<S, E>
31where
32 S: Fn(&LineSpan) -> bool,
33 E: Fn(&SectionSpan) -> bool,
34{
35 pub fn new(start: S, end: E) -> Self {
36 Self { start, end }
37 }
38}