summaryrefslogtreecommitdiff
path: root/dhall_core/src/label.rs
diff options
context:
space:
mode:
authorNadrieril2019-03-21 20:30:25 +0100
committerNadrieril2019-03-21 20:30:25 +0100
commit6cbe21b84ffd274f92791ab8dbf9af6527978688 (patch)
treef55afb9c14f639350d4186263e6ef9f8d5ba9d76 /dhall_core/src/label.rs
parent845abbb0404ac15cefeca8b6ac32d9b3f93e5987 (diff)
oops
Diffstat (limited to '')
-rw-r--r--dhall_core/src/label.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/dhall_core/src/label.rs b/dhall_core/src/label.rs
new file mode 100644
index 0000000..3633b93
--- /dev/null
+++ b/dhall_core/src/label.rs
@@ -0,0 +1,38 @@
+use std::fmt::{self, Display};
+use std::rc::Rc;
+
+// The type for labels throughout the AST
+// It owns the data because otherwise lifetimes would make recursive imports impossible
+#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
+pub struct Label(Rc<str>);
+
+impl From<String> for Label {
+ fn from(s: String) -> Self {
+ let s: &str = &s;
+ Label(s.into())
+ }
+}
+
+impl<'a> From<&'a str> for Label {
+ fn from(s: &'a str) -> Self {
+ Label(Rc::from(s))
+ }
+}
+
+impl From<Label> for String {
+ fn from(x: Label) -> String {
+ x.0.as_ref().to_owned()
+ }
+}
+
+impl Display for Label {
+ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ self.0.as_ref().fmt(f)
+ }
+}
+
+impl Label {
+ pub fn from_str(s: &str) -> Label {
+ Label(s.into())
+ }
+}