From ed2ac1713326df6b926062efcc6109a20cdf7c37 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 13 Aug 2018 14:24:22 +0300 Subject: smol_str to a crate --- crates/libsyntax2/src/yellow/green.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'crates/libsyntax2/src/yellow/green.rs') diff --git a/crates/libsyntax2/src/yellow/green.rs b/crates/libsyntax2/src/yellow/green.rs index f505b26d7..700f2704f 100644 --- a/crates/libsyntax2/src/yellow/green.rs +++ b/crates/libsyntax2/src/yellow/green.rs @@ -1,8 +1,8 @@ use std::sync::Arc; -use { - SyntaxKind, TextUnit, - smol_str::SmolStr, -}; + +use smol_str::SmolStr; + +use {SyntaxKind, TextUnit}; #[derive(Clone, Debug)] pub(crate) enum GreenNode { @@ -31,7 +31,7 @@ impl GreenNode { pub fn text_len(&self) -> TextUnit { match self { - GreenNode::Leaf { text, ..} => TextUnit::of_str(text.as_str()), + GreenNode::Leaf { text, .. } => TextUnit::of_str(text.as_str()), GreenNode::Branch(b) => b.text_len(), } } @@ -54,6 +54,13 @@ impl GreenNode { } } } + + pub fn leaf_text(&self) -> Option { + match self { + GreenNode::Leaf { text, .. } => Some(text.clone()), + GreenNode::Branch(_) => None, + } + } } #[derive(Clone, Debug)] -- cgit v1.2.3