diff options
author | Nadrieril | 2019-03-10 00:14:37 +0100 |
---|---|---|
committer | Nadrieril | 2019-03-10 00:14:37 +0100 |
commit | 19a1b8bfef47fca60ce5efc92ca479a475799d6e (patch) | |
tree | 174b84bf404a4e30764d1c6df82135239af58349 /dhall | |
parent | 3c5c6b31d3e35219f907499f094643e1bfba5db2 (diff) |
Use Rc<str> for Label
Closes #18
Diffstat (limited to '')
-rw-r--r-- | dhall_core/src/core.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index e3e1f5c..5026328 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -2,6 +2,7 @@ use std::collections::BTreeMap; use std::fmt::{self, Display}; use std::path::PathBuf; +use std::rc::Rc; /// Constants for a pure type system /// @@ -70,35 +71,36 @@ pub struct Import { // 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(String); +pub struct Label(Rc<str>); impl From<String> for Label { fn from(s: String) -> Self { - Label(s) + let s: &str = &s; + Label(s.into()) } } impl From<&'static str> for Label { fn from(s: &'static str) -> Self { - Label(s.to_owned()) + Label(s.into()) } } impl From<Label> for String { fn from(x: Label) -> String { - x.0 + x.0.as_ref().to_owned() } } impl Display for Label { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - self.0.fmt(f) + self.0.as_ref().fmt(f) } } impl Label { pub fn from_str(s: &str) -> Label { - s.to_owned().into() + Label(s.into()) } } |