diff options
Diffstat (limited to 'crates/syntax/src')
-rw-r--r-- | crates/syntax/src/ast/node_ext.rs | 4 | ||||
-rw-r--r-- | crates/syntax/src/token_text.rs | 24 |
2 files changed, 20 insertions, 8 deletions
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 88f9a0e97..bef49238f 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs | |||
@@ -40,8 +40,8 @@ fn text_of_first_token(node: &SyntaxNode) -> TokenText<'_> { | |||
40 | } | 40 | } |
41 | 41 | ||
42 | match node.green() { | 42 | match node.green() { |
43 | Cow::Borrowed(green_ref) => TokenText::Borrowed(first_token(green_ref).text()), | 43 | Cow::Borrowed(green_ref) => TokenText::borrowed(first_token(green_ref).text()), |
44 | Cow::Owned(green) => TokenText::Owned(first_token(&green).to_owned()), | 44 | Cow::Owned(green) => TokenText::owned(first_token(&green).to_owned()), |
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
diff --git a/crates/syntax/src/token_text.rs b/crates/syntax/src/token_text.rs index e29f4eea4..f3e8b321a 100644 --- a/crates/syntax/src/token_text.rs +++ b/crates/syntax/src/token_text.rs | |||
@@ -2,16 +2,28 @@ | |||
2 | 2 | ||
3 | use std::{cmp::Ordering, fmt, ops}; | 3 | use std::{cmp::Ordering, fmt, ops}; |
4 | 4 | ||
5 | pub enum TokenText<'a> { | 5 | use rowan::GreenToken; |
6 | |||
7 | pub struct TokenText<'a>(pub(crate) Repr<'a>); | ||
8 | |||
9 | pub(crate) enum Repr<'a> { | ||
6 | Borrowed(&'a str), | 10 | Borrowed(&'a str), |
7 | Owned(rowan::GreenToken), | 11 | Owned(GreenToken), |
8 | } | 12 | } |
9 | 13 | ||
10 | impl TokenText<'_> { | 14 | impl<'a> TokenText<'a> { |
15 | pub(crate) fn borrowed(text: &'a str) -> Self { | ||
16 | TokenText(Repr::Borrowed(text)) | ||
17 | } | ||
18 | |||
19 | pub(crate) fn owned(green: GreenToken) -> Self { | ||
20 | TokenText(Repr::Owned(green)) | ||
21 | } | ||
22 | |||
11 | pub fn as_str(&self) -> &str { | 23 | pub fn as_str(&self) -> &str { |
12 | match self { | 24 | match self.0 { |
13 | TokenText::Borrowed(it) => *it, | 25 | Repr::Borrowed(it) => it, |
14 | TokenText::Owned(green) => green.text(), | 26 | Repr::Owned(ref green) => green.text(), |
15 | } | 27 | } |
16 | } | 28 | } |
17 | } | 29 | } |