diff options
Diffstat (limited to 'crates/syntax/src/token_text.rs')
-rw-r--r-- | crates/syntax/src/token_text.rs | 24 |
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 | ||
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 | } |