summaryrefslogtreecommitdiff
path: root/dhall/src/syntax/ast/label.rs
diff options
context:
space:
mode:
authorNadrieril Feneanar2019-12-20 19:39:16 +0000
committerGitHub2019-12-20 19:39:16 +0000
commitde0dd59204e979e29445d634a0739394110261ef (patch)
treea75ce010c7ea771a03cb51cc2b828dad6ea1a9f7 /dhall/src/syntax/ast/label.rs
parent91ef0cf697d56c91a8d15937aa4669dc221cd6c1 (diff)
parent64cca1837cc97b7679c4e2ffd54a22ad50f05cfd (diff)
Merge pull request #118 from Nadrieril/clarify-types
Clarify naming and file organization
Diffstat (limited to 'dhall/src/syntax/ast/label.rs')
-rw-r--r--dhall/src/syntax/ast/label.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/dhall/src/syntax/ast/label.rs b/dhall/src/syntax/ast/label.rs
new file mode 100644
index 0000000..43c3f53
--- /dev/null
+++ b/dhall/src/syntax/ast/label.rs
@@ -0,0 +1,34 @@
+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 Label {
+ pub fn from_str(s: &str) -> Label {
+ Label(s.into())
+ }
+ pub fn as_ref(&self) -> &str {
+ self.0.as_ref()
+ }
+}