diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-21 15:14:53 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-21 15:14:53 +0100 |
commit | ba6cf638fbf3d0a025e804f2d354d91abc8afd28 (patch) | |
tree | a1d66d2b8e06d2e32f9a4d0ce9857948dd981459 /crates/ra_text_edit/src/lib.rs | |
parent | 3cba0dc26b707bebc1865671fd2c5139c1e1c537 (diff) | |
parent | ef0da3bbeccdaab3813a1f6a17c566ca9087615f (diff) |
Merge #4553
4553: Cleanup r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_text_edit/src/lib.rs')
-rw-r--r-- | crates/ra_text_edit/src/lib.rs | 16 |
1 files changed, 12 insertions, 4 deletions
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 @@ | |||
3 | //! `rust-analyzer` never mutates text itself and only sends diffs to clients, | 3 | //! `rust-analyzer` never mutates text itself and only sends diffs to clients, |
4 | //! so `TextEdit` is the ultimate representation of the work done by | 4 | //! so `TextEdit` is the ultimate representation of the work done by |
5 | //! rust-analyzer. | 5 | //! rust-analyzer. |
6 | use std::{slice, vec}; | ||
6 | 7 | ||
7 | pub use text_size::{TextRange, TextSize}; | 8 | pub use text_size::{TextRange, TextSize}; |
8 | 9 | ||
@@ -71,17 +72,24 @@ impl TextEdit { | |||
71 | TextEdit { indels } | 72 | TextEdit { indels } |
72 | } | 73 | } |
73 | 74 | ||
75 | pub fn len(&self) -> usize { | ||
76 | self.indels.len() | ||
77 | } | ||
78 | |||
74 | pub fn is_empty(&self) -> bool { | 79 | pub fn is_empty(&self) -> bool { |
75 | self.indels.is_empty() | 80 | self.indels.is_empty() |
76 | } | 81 | } |
77 | 82 | ||
78 | // FXME: impl IntoIter instead | 83 | pub fn iter(&self) -> slice::Iter<'_, Indel> { |
79 | pub fn as_indels(&self) -> &[Indel] { | 84 | self.indels.iter() |
80 | &self.indels | 85 | } |
86 | |||
87 | pub fn into_iter(self) -> vec::IntoIter<Indel> { | ||
88 | self.indels.into_iter() | ||
81 | } | 89 | } |
82 | 90 | ||
83 | pub fn apply(&self, text: &mut String) { | 91 | pub fn apply(&self, text: &mut String) { |
84 | match self.indels.len() { | 92 | match self.len() { |
85 | 0 => return, | 93 | 0 => return, |
86 | 1 => { | 94 | 1 => { |
87 | self.indels[0].apply(text); | 95 | self.indels[0].apply(text); |