File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -390,16 +390,25 @@ impl str {
390390 /// # Examples
391391 ///
392392 /// ```
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;
400394 ///
395+ /// let mut v = String::from("hello");
396+ /// // correct length
397+ /// assert!(v.get_mut(0..5).is_some());
401398 /// // out of bounds
402399 /// 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);
403412 /// ```
404413 #[ stable( feature = "str_checked_slicing" , since = "1.20.0" ) ]
405414 #[ inline]
You can’t perform that action at this time.
0 commit comments