1#![allow(clippy::len_without_is_empty)]
3
4use std::cmp::Ordering;
5use std::fmt::{Display, Formatter};
6
7#[derive(Debug, Copy, Clone, PartialEq)]
9pub struct Coords {
10 pub absolute: usize,
12 pub line: usize,
14 pub column: usize,
16}
17
18impl Display for Coords {
19 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
20 write!(
21 f,
22 "[abs: {}, line: {}, column: {}]",
23 self.absolute, self.line, self.column
24 )
25 }
26}
27
28impl Default for Coords {
29 fn default() -> Self {
31 Coords {
32 absolute: 0,
33 line: 0,
34 column: 0,
35 }
36 }
37}
38
39impl Eq for Coords {}
40
41impl PartialOrd<Self> for Coords {
42 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
43 match self.absolute.cmp(&other.absolute) {
44 Ordering::Less => Some(Ordering::Less),
45 Ordering::Equal => Some(Ordering::Equal),
46 Ordering::Greater => Some(Ordering::Greater),
47 }
48 }
49}
50
51impl Ord for Coords {
52 fn cmp(&self, other: &Self) -> Ordering {
53 self.absolute.cmp(&other.absolute)
54 }
55}
56
57#[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd)]
59pub struct Span {
60 pub start: Coords,
62 pub end: Coords,
64}
65
66impl Span {}
67
68impl Display for Span {
69 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
70 write!(f, "start: {}, end: {}", self.start, self.end,)
71 }
72}