1use core::borrow::Borrow;
14
15use crate::{Span, Spanned};
16
17#[derive(Clone, Debug)]
20pub struct Identifier<'a> {
21 pub value: &'a str,
23 pub span: Span,
25}
26
27impl<'a> PartialEq for Identifier<'a> {
28 fn eq(&self, other: &Self) -> bool {
29 self.value == other.value
30 }
31}
32impl<'a> Eq for Identifier<'a> {}
33
34impl<'a> PartialOrd for Identifier<'a> {
35 fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
36 Some(self.cmp(other))
37 }
38}
39
40impl<'a> Ord for Identifier<'a> {
41 fn cmp(&self, other: &Self) -> core::cmp::Ordering {
42 self.value.cmp(other.value)
43 }
44}
45
46impl<'a> alloc::fmt::Display for Identifier<'a> {
47 fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result {
48 self.value.fmt(f)
49 }
50}
51
52impl<'a> Borrow<str> for Identifier<'a> {
53 fn borrow(&self) -> &str {
54 self.value
55 }
56}
57
58impl<'a> Identifier<'a> {
59 pub fn new(value: &'a str, span: Span) -> Self {
61 Identifier { value, span }
62 }
63
64 pub fn as_str(&self) -> &'a str {
66 self.value
67 }
68}
69
70impl<'a> core::ops::Deref for Identifier<'a> {
71 type Target = str;
72
73 fn deref(&self) -> &'a Self::Target {
74 self.value
75 }
76}
77
78impl<'a> Spanned for Identifier<'a> {
79 fn span(&self) -> Span {
80 self.span.span()
81 }
82}