File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -292,6 +292,18 @@ impl<'a> DoubleEndedIterator for Chars<'a> {
292
292
}
293
293
}
294
294
295
+ impl < ' a > Chars < ' a > {
296
+ /// View the underlying data as a subslice of the original data.
297
+ ///
298
+ /// This has the same lifetime as the original slice, and so the
299
+ /// iterator can continue to be used while this exists.
300
+ #[ unstable( feature = "iter_to_slice" , issue = "27775" ) ]
301
+ #[ inline]
302
+ pub fn as_str ( & self ) -> & ' a str {
303
+ unsafe { from_utf8_unchecked ( self . iter . as_slice ( ) ) }
304
+ }
305
+ }
306
+
295
307
/// Iterator for a string's characters and their byte offsets.
296
308
#[ derive( Clone ) ]
297
309
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -339,6 +351,18 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> {
339
351
}
340
352
}
341
353
354
+ impl < ' a > CharIndices < ' a > {
355
+ /// View the underlying data as a subslice of the original data.
356
+ ///
357
+ /// This has the same lifetime as the original slice, and so the
358
+ /// iterator can continue to be used while this exists.
359
+ #[ unstable( feature = "iter_to_slice" , issue = "27775" ) ]
360
+ #[ inline]
361
+ pub fn as_str ( & self ) -> & ' a str {
362
+ self . iter . as_str ( )
363
+ }
364
+ }
365
+
342
366
/// External iterator for a string's bytes.
343
367
/// Use with the `std::iter` module.
344
368
///
You can’t perform that action at this time.
0 commit comments