1#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Ord, PartialOrd, Hash)]
3pub struct Span {
4 start: usize,
5 end: usize,
6}
7
8impl Span {
9 #[must_use]
10 pub fn new(start: usize, end: usize) -> Self {
11 Self { start, end }
12 }
13
14 #[must_use]
16 pub fn start(self) -> usize {
17 self.start
18 }
19
20 #[must_use]
22 pub fn end(self) -> usize {
23 self.end
24 }
25
26 #[must_use]
27 pub fn range(self) -> std::ops::Range<usize> {
28 self.start..self.end
29 }
30}
31
32impl std::ops::Add<usize> for Span {
33 type Output = Self;
34
35 fn add(self, other: usize) -> Self {
36 Self {
37 start: self.start + other,
38 end: self.end + other,
39 }
40 }
41}
42
43impl From<&Span> for Span {
44 fn from(span: &Span) -> Self {
45 *span
46 }
47}
48
49impl From<(usize, usize)> for Span {
50 fn from((start, end): (usize, usize)) -> Self {
51 Self { start, end }
52 }
53}
54
55#[must_use]
56pub fn span(start: usize, end: usize) -> Span {
57 Span { start, end }
58}