From a4781e2c743e55c97483a7c44080e339e34b5149 Mon Sep 17 00:00:00 2001 From: MDeiml Date: Tue, 26 Jul 2022 10:19:14 +0200 Subject: [PATCH] Better documentation for fragment and slice methods --- helix-core/src/selection.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs index aacaa1da4a51..59bd736e60fc 100644 --- a/helix-core/src/selection.rs +++ b/helix-core/src/selection.rs @@ -222,12 +222,20 @@ impl Range { // groupAt - /// Consider using `slice` instead. + /// Returns the text inside this range given the text of the whole buffer. + /// + /// The returned `Cow` is a reference if the range of text is inside a single + /// chunk of the rope. Otherwise a copy of the text is returned. Consider + /// using `slice` instead if you do not need a `Cow` or `String` to avoid copying. #[inline] pub fn fragment<'a, 'b: 'a>(&'a self, text: RopeSlice<'b>) -> Cow<'b, str> { self.slice(text).into() } + /// Returns the text inside this range given the text of the whole buffer. + /// + /// The returned value is a reference to the passed slice. This method never + /// copies any contents. #[inline] pub fn slice<'a, 'b: 'a>(&'a self, text: RopeSlice<'b>) -> RopeSlice<'b> { text.slice(self.from()..self.to())