]> Witch of Git - ess/blob - src/span.rs
Split the project into multiple modules
[ess] / src / span.rs
1 //! A `Span` represents a location in source file.
2
3 pub trait Span {
4 type Begin;
5
6 fn offset(&self, begin: Self::Begin) -> Self;
7 fn begin(&self) -> Self::Begin;
8 fn union(&self, other: &Self) -> Self;
9 }
10
11 pub type ByteSpan = (usize, usize);
12
13 impl Span for ByteSpan {
14 type Begin = usize;
15
16 fn offset(&self, begin: Self::Begin) -> Self {
17 (self.0 + begin, self.1 + begin)
18 }
19
20 fn begin(&self) -> Self::Begin {
21 self.0
22 }
23
24 fn union(&self, other: &Self) -> Self {
25 use std::cmp::{min, max};
26 (min(self.0, other.0), max(self.1, other.1))
27 }
28 }
29