summaryrefslogtreecommitdiff
path: root/src/syntax/ident.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-10 13:07:39 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-10 13:07:39 +0200
commit36b3067c19c8743032a44f888ee48702b88d135b (patch)
tree89893f4501109b35bb6498b93bda4f3cc82dba40 /src/syntax/ident.rs
parent9950627789358b4d46c7fd8ba20d1428aee7bf01 (diff)
Eco string 🌱
Diffstat (limited to 'src/syntax/ident.rs')
-rw-r--r--src/syntax/ident.rs14
1 files changed, 9 insertions, 5 deletions
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<Span>,
) -> Option<Self> {
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<str> 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()
}
}