ass_core/parser/ast/
span.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize))]
9pub struct Span {
10 pub start: usize,
12 pub end: usize,
14 pub line: u32,
16 pub column: u32,
18}
19
20impl Span {
21 #[must_use]
23 pub const fn new(start: usize, end: usize, line: u32, column: u32) -> Self {
24 Self {
25 start,
26 end,
27 line,
28 column,
29 }
30 }
31
32 #[must_use]
34 pub const fn contains(&self, offset: usize) -> bool {
35 offset >= self.start && offset < self.end
36 }
37
38 #[must_use]
40 pub fn merge(&self, other: &Self) -> Self {
41 use core::cmp::Ordering;
42
43 Self {
44 start: self.start.min(other.start),
45 end: self.end.max(other.end),
46 line: self.line.min(other.line),
47 column: match self.line.cmp(&other.line) {
48 Ordering::Less => self.column,
49 Ordering::Greater => other.column,
50 Ordering::Equal => self.column.min(other.column),
51 },
52 }
53 }
54}