From 0f678a9bebd493c50f472e42368372535d6a4660 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 9 Jun 2026 09:16:14 -0400 Subject: [PATCH] stdx: Add must_use and inline attributes to regex and grapheme helpers --- helix-stdx/src/rope.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/helix-stdx/src/rope.rs b/helix-stdx/src/rope.rs index 282ce22e..c397fc38 100644 --- a/helix-stdx/src/rope.rs +++ b/helix-stdx/src/rope.rs @@ -13,11 +13,14 @@ use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete}; pub trait RopeSliceExt<'a>: Sized { fn ends_with(self, text: &str) -> bool; fn starts_with(self, text: &str) -> bool; + #[must_use] fn regex_input(self) -> RegexInput>; + #[must_use] fn regex_input_at_bytes>( self, byte_range: R, ) -> RegexInput>; + #[must_use] fn regex_input_at>(self, char_range: R) -> RegexInput>; fn first_non_whitespace_char(self) -> Option; fn last_non_whitespace_char(self) -> Option; @@ -137,6 +140,8 @@ pub trait RopeSliceExt<'a>: Sized { /// let graphemes: Vec<_> = text.graphemes().collect(); /// assert_eq!(graphemes.as_slice(), &["πŸ˜Άβ€πŸŒ«οΈ", "πŸ΄β€β˜ οΈ", "πŸ–ΌοΈ"]); /// ``` + #[inline] + #[must_use] fn graphemes(self) -> RopeGraphemes<'a> { self.graphemes_at(0) } @@ -154,6 +159,7 @@ pub trait RopeSliceExt<'a>: Sized { /// let graphemes: Vec<_> = text.graphemes_rev().collect(); /// assert_eq!(graphemes.as_slice(), &["πŸ–ΌοΈ", "πŸ΄β€β˜ οΈ", "πŸ˜Άβ€πŸŒ«οΈ"]); /// ``` + #[must_use] fn graphemes_rev(self) -> RopeGraphemes<'a>; /// Returns an iterator over the grapheme clusters in the slice at the given byte index. /// @@ -170,11 +176,14 @@ pub trait RopeSliceExt<'a>: Sized { /// let graphemes: Vec<_> = text.slice(..).graphemes_at(27).reversed().collect(); /// assert_eq!(graphemes.as_slice(), &["πŸ΄β€β˜ οΈ", "πŸ˜Άβ€πŸŒ«οΈ"]); /// ``` + #[must_use] fn graphemes_at(self, byte_idx: usize) -> RopeGraphemes<'a>; /// Returns an iterator over the grapheme clusters in a rope and the byte index where each /// grapheme cluster starts. /// /// Same as `grapheme_indices_at(0)`. + #[inline] + #[must_use] fn grapheme_indices(self) -> RopeGraphemeIndices<'a> { self.grapheme_indices_at(0) } @@ -199,6 +208,7 @@ pub trait RopeSliceExt<'a>: Sized { /// &[(27, "πŸ–ΌοΈ".into()), (14, "πŸ΄β€β˜ οΈ".into()), (0, "πŸ˜Άβ€πŸŒ«οΈ".into())] /// ); /// ``` + #[must_use] fn grapheme_indices_at(self, byte_idx: usize) -> RopeGraphemeIndices<'a>; /// Finds the byte index of the next grapheme boundary after `byte_idx`. /// -- 2.51.2