From 5f57491c981530103e1e26dcd280e1a2df10f853 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 May 2020 15:56:18 +0200 Subject: Cleanup TextEdit --- crates/ra_text_edit/src/lib.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'crates/ra_text_edit') diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs index c4f945101..199fd1096 100644 --- a/crates/ra_text_edit/src/lib.rs +++ b/crates/ra_text_edit/src/lib.rs @@ -3,6 +3,7 @@ //! `rust-analyzer` never mutates text itself and only sends diffs to clients, //! so `TextEdit` is the ultimate representation of the work done by //! rust-analyzer. +use std::{slice, vec}; pub use text_size::{TextRange, TextSize}; @@ -71,17 +72,24 @@ impl TextEdit { TextEdit { indels } } + pub fn len(&self) -> usize { + self.indels.len() + } + pub fn is_empty(&self) -> bool { self.indels.is_empty() } - // FXME: impl IntoIter instead - pub fn as_indels(&self) -> &[Indel] { - &self.indels + pub fn iter(&self) -> slice::Iter<'_, Indel> { + self.indels.iter() + } + + pub fn into_iter(self) -> vec::IntoIter { + self.indels.into_iter() } pub fn apply(&self, text: &mut String) { - match self.indels.len() { + match self.len() { 0 => return, 1 => { self.indels[0].apply(text); -- cgit v1.2.3