[ruff] Add `TextRange::to_std_range`

This can already be accomplished via a `From` impl (and indeed,
that's how this is implemented). But in a generic context, the
turbo-fishing that needs to be applied is quite annoying.
This commit is contained in:
Andrew Gallant 2025-09-16 12:41:11 -04:00 committed by Andrew Gallant
parent da5eb85087
commit 61a49c89eb
1 changed files with 16 additions and 0 deletions

View File

@ -425,6 +425,22 @@ impl TextRange {
} }
} }
/// Conversion methods.
impl TextRange {
/// A convenience routine for converting this range to a
/// standard library range that satisfies the `RangeBounds`
/// trait.
///
/// This is also available as a `From` trait implementation,
/// but this method avoids the need to specify types to help
/// inference.
#[inline]
#[must_use]
pub fn to_std_range(&self) -> Range<usize> {
(*self).into()
}
}
impl Index<TextRange> for str { impl Index<TextRange> for str {
type Output = str; type Output = str;
#[inline] #[inline]