Skip to content

Commit c430fa8

Browse files
author
toidiu
committed
documentation update to demonstrate mutability
1 parent 088216f commit c430fa8

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/liballoc/str.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -362,16 +362,25 @@ impl str {
362362
/// # Examples
363363
///
364364
/// ```
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;
372366
///
367+
/// let mut v = String::from("hello");
368+
/// // correct length
369+
/// assert!(v.get_mut(0..5).is_some());
373370
/// // out of bounds
374371
/// 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);
375384
/// ```
376385
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
377386
#[inline]

0 commit comments

Comments
 (0)