string_sections/
section_span.rs1use std::ops::{Deref, Range};
2
3use crate::LineSpan;
4
5#[derive(PartialEq, Eq, Clone, Copy)]
6pub struct SectionSpan<'a> {
7 pub start_line: LineSpan<'a>,
8 pub end_line: LineSpan<'a>,
9}
10
11const LBR: &[char] = &['\n', '\r'];
12
13impl<'a> SectionSpan<'a> {
14 pub fn inner_range(&self) -> Range<usize> {
16 self.start_line.end..self.end_line.start
17 }
18
19 pub fn outer_range(&self) -> Range<usize> {
21 self.start_line.start..self.end_line.end
22 }
23
24 pub fn as_str(&self) -> &'a str {
26 &self.start_line.text[self.inner_range()].trim_matches(LBR)
27 }
28}
29
30impl<'a> Deref for SectionSpan<'a> {
31 type Target = str;
32
33 fn deref(&self) -> &Self::Target {
34 self.as_str()
35 }
36}