1use core::fmt;
2use std::{cmp::Ordering, hash::Hash, hash::Hasher};
3
4#[derive(Clone)]
10pub struct Id {
11 original: String,
12 lower_case: String,
13}
14
15impl Id {
16 pub fn from(str: &str) -> Id {
18 Id {
19 original: String::from(str),
20 lower_case: String::from(str).to_lowercase(),
21 }
22 }
23
24 pub fn clone(&self) -> Id {
26 Id::from(self.original.as_str())
27 }
28
29 pub fn to_string(&self) -> String {
35 String::from(&self.lower_case)
36 }
37
38 pub fn lower_case(&self) -> &String {
40 &self.lower_case
41 }
42}
43
44impl PartialEq for Id {
45 fn eq(&self, other: &Self) -> bool {
46 self.lower_case == other.lower_case
47 }
48}
49impl Eq for Id {}
50
51impl Hash for Id {
52 fn hash<H: Hasher>(&self, state: &mut H) {
53 self.lower_case.hash(state);
54 }
55}
56
57impl Ord for Id {
58 fn cmp(&self, other: &Self) -> Ordering {
59 self.lower_case.cmp(&other.lower_case)
60 }
61}
62
63impl PartialOrd for Id {
64 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
65 Some(self.cmp(other))
66 }
67}
68
69impl fmt::Debug for Id {
70 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71 f.write_str(&self.original)
72 }
73}
74
75impl fmt::Display for Id {
76 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
77 f.write_str(&self.original)
78 }
79}
80
81#[derive(Debug, Clone)]
83pub struct SourceLoc {
84 pub offset: usize,
85}
86
87impl SourceLoc {
88 pub fn new(offset: usize) -> SourceLoc {
89 SourceLoc { offset: offset }
90 }
91}
92
93impl PartialEq for SourceLoc {
94 fn eq(&self, other: &Self) -> bool {
95 true
99 }
100}
101impl Eq for SourceLoc {}