Skip to content

Commit 2baad9e

Browse files
authored
Merge pull request #19 from RustPython/identifier
A few more Identifier utilities
2 parents 5b2af30 + 2af9805 commit 2baad9e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

ast/src/builtin.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ impl Identifier {
1515
}
1616
}
1717

18+
impl Identifier {
19+
#[inline]
20+
pub fn as_str(&self) -> &str {
21+
self.0.as_str()
22+
}
23+
}
24+
1825
impl std::cmp::PartialEq<str> for Identifier {
1926
#[inline]
2027
fn eq(&self, other: &str) -> bool {
@@ -30,9 +37,23 @@ impl std::cmp::PartialEq<String> for Identifier {
3037
}
3138

3239
impl std::ops::Deref for Identifier {
33-
type Target = String;
40+
type Target = str;
3441
#[inline]
3542
fn deref(&self) -> &Self::Target {
43+
self.0.as_str()
44+
}
45+
}
46+
47+
impl AsRef<str> for Identifier {
48+
#[inline]
49+
fn as_ref(&self) -> &str {
50+
self.0.as_str()
51+
}
52+
}
53+
54+
impl AsRef<String> for Identifier {
55+
#[inline]
56+
fn as_ref(&self) -> &String {
3657
&self.0
3758
}
3859
}

0 commit comments

Comments
 (0)