Skip to content

Commit

Permalink
Better documentation for fragment and slice methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeiml committed Aug 2, 2022
1 parent bdd2108 commit a4781e2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion helix-core/src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit a4781e2

Please sign in to comment.