aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/syntax/src/ast/node_ext.rs4
-rw-r--r--crates/syntax/src/token_text.rs24
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
3use std::{cmp::Ordering, fmt, ops}; 3use std::{cmp::Ordering, fmt, ops};
4 4
5pub enum TokenText<'a> { 5use rowan::GreenToken;
6
7pub struct TokenText<'a>(pub(crate) Repr<'a>);
8
9pub(crate) enum Repr<'a> {
6 Borrowed(&'a str), 10 Borrowed(&'a str),
7 Owned(rowan::GreenToken), 11 Owned(GreenToken),
8} 12}
9 13
10impl TokenText<'_> { 14impl<'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}