From 36b3067c19c8743032a44f888ee48702b88d135b Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 10 Jul 2021 13:07:39 +0200 Subject: =?UTF-8?q?Eco=20string=20=F0=9F=8C=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/ident.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/syntax/ident.rs') diff --git a/src/syntax/ident.rs b/src/syntax/ident.rs index a46ad232..b1328bbe 100644 --- a/src/syntax/ident.rs +++ b/src/syntax/ident.rs @@ -3,6 +3,7 @@ use std::ops::Deref; use unicode_xid::UnicodeXID; use super::Span; +use crate::eco::EcoString; /// An unicode identifier with a few extra permissible characters. /// @@ -16,7 +17,7 @@ pub struct Ident { /// The source code location. pub span: Span, /// The identifier string. - pub string: String, + pub string: EcoString, } impl Ident { @@ -26,7 +27,10 @@ impl Ident { span: impl Into, ) -> Option { if is_ident(string.as_ref()) { - Some(Self { span: span.into(), string: string.into() }) + Some(Self { + span: span.into(), + string: EcoString::from_str(string), + }) } else { None } @@ -34,13 +38,13 @@ impl Ident { /// Return a reference to the underlying string. pub fn as_str(&self) -> &str { - self.string.as_str() + self } } impl AsRef for Ident { fn as_ref(&self) -> &str { - self.as_str() + self } } @@ -48,7 +52,7 @@ impl Deref for Ident { type Target = str; fn deref(&self) -> &Self::Target { - self.as_str() + self.string.as_str() } } -- cgit v1.2.3