mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Hide implementation details of TokenText
This commit is contained in:
parent
d9b4ac8128
commit
0a156c80af
2 changed files with 20 additions and 8 deletions
|
@ -40,8 +40,8 @@ fn text_of_first_token(node: &SyntaxNode) -> TokenText<'_> {
|
|||
}
|
||||
|
||||
match node.green() {
|
||||
Cow::Borrowed(green_ref) => TokenText::Borrowed(first_token(green_ref).text()),
|
||||
Cow::Owned(green) => TokenText::Owned(first_token(&green).to_owned()),
|
||||
Cow::Borrowed(green_ref) => TokenText::borrowed(first_token(green_ref).text()),
|
||||
Cow::Owned(green) => TokenText::owned(first_token(&green).to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,16 +2,28 @@
|
|||
|
||||
use std::{cmp::Ordering, fmt, ops};
|
||||
|
||||
pub enum TokenText<'a> {
|
||||
use rowan::GreenToken;
|
||||
|
||||
pub struct TokenText<'a>(pub(crate) Repr<'a>);
|
||||
|
||||
pub(crate) enum Repr<'a> {
|
||||
Borrowed(&'a str),
|
||||
Owned(rowan::GreenToken),
|
||||
Owned(GreenToken),
|
||||
}
|
||||
|
||||
impl<'a> TokenText<'a> {
|
||||
pub(crate) fn borrowed(text: &'a str) -> Self {
|
||||
TokenText(Repr::Borrowed(text))
|
||||
}
|
||||
|
||||
pub(crate) fn owned(green: GreenToken) -> Self {
|
||||
TokenText(Repr::Owned(green))
|
||||
}
|
||||
|
||||
impl TokenText<'_> {
|
||||
pub fn as_str(&self) -> &str {
|
||||
match self {
|
||||
TokenText::Borrowed(it) => *it,
|
||||
TokenText::Owned(green) => green.text(),
|
||||
match self.0 {
|
||||
Repr::Borrowed(it) => it,
|
||||
Repr::Owned(ref green) => green.text(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue