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 @@ -390,16 +390,25 @@ impl str {
390
390
/// # Examples
391
391
///
392
392
/// ```
393
- /// let mut v = String::from("🗻∈🌏");
394
- ///
395
- /// assert_eq!(Some("🗻"), v.get_mut(0..4).map(|v| &*v));
396
- ///
397
- /// // indices not on UTF-8 sequence boundaries
398
- /// assert!(v.get_mut(1..).is_none());
399
- /// assert!(v.get_mut(..8).is_none());
393
+ /// use std::ascii::AsciiExt;
400
394
///
395
+ /// let mut v = String::from("hello");
396
+ /// // correct length
397
+ /// assert!(v.get_mut(0..5).is_some());
401
398
/// // out of bounds
402
399
/// assert!(v.get_mut(..42).is_none());
400
+ /// assert_eq!(Some("he"), v.get_mut(0..2).map(|v| &*v));
401
+ ///
402
+ /// assert_eq!("hello", v);
403
+ /// {
404
+ /// let s = v.get_mut(0..2);
405
+ /// let s = s.map(|s| {
406
+ /// s.make_ascii_uppercase();
407
+ /// &*s
408
+ /// });
409
+ /// assert_eq!(Some("HE"), s);
410
+ /// }
411
+ /// assert_eq!("HEllo", v);
403
412
/// ```
404
413
#[ stable( feature = "str_checked_slicing" , since = "1.20.0" ) ]
405
414
#[ inline]
You can’t perform that action at this time.
0 commit comments