Skip to content

Commit 8a7d93b

Browse files
Rollup merge of #44467 - toidiu:ak-44382, r=frewsxcv
documentation update to demonstrate mutability #44467 - demonstrate correct implementation returns `Some` - demonstrate out of bounds returns `None` - demonstrate mutability
2 parents dcc1d14 + c430fa8 commit 8a7d93b

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
@@ -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]

0 commit comments

Comments
 (0)