From 0a156c80af8df24543323bdf47d75c5a339cfe48 Mon Sep 17 00:00:00 2001 From: Dawer <7803845+iDawer@users.noreply.github.com> Date: Thu, 6 May 2021 10:07:06 +0500 Subject: Hide implementation details of TokenText --- crates/syntax/src/token_text.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'crates/syntax/src/token_text.rs') 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 @@ 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 TokenText<'_> { +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)) + } + 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(), } } } -- cgit v1.2.3