From 3c92bad9a7cd6b880de197806443ffcce2cac9d8 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 31 Jul 2021 22:59:14 +0200 Subject: Pretty-printed diagnostics with traceback --- src/util/eco.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/util') diff --git a/src/util/eco.rs b/src/util/eco.rs index 7fe1ac9c..00f87872 100644 --- a/src/util/eco.rs +++ b/src/util/eco.rs @@ -193,6 +193,24 @@ impl From<&String> for EcoString { } } +impl From for String { + fn from(s: EcoString) -> Self { + match s.0 { + Repr::Small { .. } => s.as_str().to_owned(), + Repr::Large(rc) => match Rc::try_unwrap(rc) { + Ok(string) => string, + Err(rc) => (*rc).clone(), + }, + } + } +} + +impl From<&EcoString> for String { + fn from(s: &EcoString) -> Self { + s.as_str().to_owned() + } +} + impl Deref for EcoString { type Target = str; -- cgit v1.2.3