File tree 1 file changed +16
-7
lines changed
1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -362,16 +362,25 @@ impl str {
362
362
/// # Examples
363
363
///
364
364
/// ```
365
- /// let mut v = String::from("🗻∈🌏");
366
- ///
367
- /// assert_eq!(Some("🗻"), v.get_mut(0..4).map(|v| &*v));
368
- ///
369
- /// // indices not on UTF-8 sequence boundaries
370
- /// assert!(v.get_mut(1..).is_none());
371
- /// assert!(v.get_mut(..8).is_none());
365
+ /// use std::ascii::AsciiExt;
372
366
///
367
+ /// let mut v = String::from("hello");
368
+ /// // correct length
369
+ /// assert!(v.get_mut(0..5).is_some());
373
370
/// // out of bounds
374
371
/// assert!(v.get_mut(..42).is_none());
372
+ /// assert_eq!(Some("he"), v.get_mut(0..2).map(|v| &*v));
373
+ ///
374
+ /// assert_eq!("hello", v);
375
+ /// {
376
+ /// let s = v.get_mut(0..2);
377
+ /// let s = s.map(|s| {
378
+ /// s.make_ascii_uppercase();
379
+ /// &*s
380
+ /// });
381
+ /// assert_eq!(Some("HE"), s);
382
+ /// }
383
+ /// assert_eq!("HEllo", v);
375
384
/// ```
376
385
#[ stable( feature = "str_checked_slicing" , since = "1.20.0" ) ]
377
386
#[ inline]
You can’t perform that action at this time.
0 commit comments