diff options
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/eco.rs | 18 |
1 files changed, 18 insertions, 0 deletions
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<EcoString> 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; |
