string_sections/
prelude.rs1use crate::{LineSpan, SectionFinder, SectionFnFinder, SectionIter, SectionSpan};
2
3pub trait Sections {
4 fn sections_find<'a, F: SectionFinder>(&'a self, finder: F) -> SectionIter<'a, F>;
6 fn sections<'a, S, E>(&'a self, start: S, end: E) -> SectionIter<'a, SectionFnFinder<S, E>>
8 where
9 S: Fn(&LineSpan) -> bool,
10 E: Fn(&SectionSpan) -> bool;
11}
12
13impl Sections for str {
14 fn sections_find<'a, F: SectionFinder>(&'a self, finder: F) -> SectionIter<'a, F> {
15 SectionIter {
16 text: self,
17 iter: self.lines(),
18 finder,
19 }
20 }
21
22 fn sections<'a, S, E>(&'a self, start: S, end: E) -> SectionIter<'a, SectionFnFinder<S, E>>
23 where
24 S: Fn(&LineSpan) -> bool,
25 E: Fn(&SectionSpan) -> bool,
26 {
27 SectionIter {
28 text: self,
29 iter: self.lines(),
30 finder: SectionFnFinder::new(start, end),
31 }
32 }
33}