Skip to content

Commit 5ef8391

Browse files
committed
Re-add Index<TextRange> for String
1 parent aa8e477 commit 5ef8391

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/range.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,29 @@ impl TextRange {
305305
impl Index<TextRange> for str {
306306
type Output = str;
307307
#[inline]
308-
fn index(&self, index: TextRange) -> &Self::Output {
308+
fn index(&self, index: TextRange) -> &str {
309+
&self[Range::<usize>::from(index)]
310+
}
311+
}
312+
313+
impl Index<TextRange> for String {
314+
type Output = str;
315+
#[inline]
316+
fn index(&self, index: TextRange) -> &str {
309317
&self[Range::<usize>::from(index)]
310318
}
311319
}
312320

313321
impl IndexMut<TextRange> for str {
314322
#[inline]
315-
fn index_mut(&mut self, index: TextRange) -> &mut Self::Output {
323+
fn index_mut(&mut self, index: TextRange) -> &mut str {
324+
&mut self[Range::<usize>::from(index)]
325+
}
326+
}
327+
328+
impl IndexMut<TextRange> for String {
329+
#[inline]
330+
fn index_mut(&mut self, index: TextRange) -> &mut str {
316331
&mut self[Range::<usize>::from(index)]
317332
}
318333
}

0 commit comments

Comments
 (0)