aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src/token_text.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax/src/token_text.rs')
-rw-r--r--crates/syntax/src/token_text.rs24
1 files changed, 18 insertions, 6 deletions
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}