1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#[cfg(doc)]
pub mod reference;
pub mod ast;
mod checker;
mod execution;
pub mod functions;
pub mod graph;
mod lazy_execution;
pub mod parse_error;
mod parser;
mod variables;
pub use execution::ExecutionConfig;
pub use execution::ExecutionError;
pub use parser::Location;
pub use parser::ParseError;
pub use variables::Globals as Variables;
use std::borrow::Borrow;
use std::hash::Hash;
use std::ops::Deref;
use std::rc::Rc;
use serde::Serialize;
use serde::Serializer;
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Identifier(Rc<String>);
impl Identifier {
pub fn as_str(&self) -> &str {
self.0.as_str()
}
pub fn into_string(mut self) -> String {
Rc::make_mut(&mut self.0);
Rc::try_unwrap(self.0).unwrap()
}
}
impl Borrow<str> for Identifier {
fn borrow(&self) -> &str {
self.as_str()
}
}
impl Deref for Identifier {
type Target = str;
fn deref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for Identifier {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl From<&str> for Identifier {
fn from(value: &str) -> Identifier {
Identifier(Rc::new(String::from(value)))
}
}
impl Hash for Identifier {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.0.hash(state);
}
}
impl PartialEq<str> for Identifier {
fn eq(&self, other: &str) -> bool {
self.as_str() == other
}
}
impl<'a> PartialEq<&'a str> for Identifier {
fn eq(&self, other: &&'a str) -> bool {
self.as_str() == *other
}
}
impl Serialize for Identifier {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(self.as_str())
}
}