about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2017-09-10 14:03:32 +0200
committerGitHub <noreply@github.com>2017-09-10 14:03:32 +0200
commit8a7d93bf6f5b1a699bafec6f59964a3962b2e927 (patch)
tree3ce1c5941134231fa5a5309a78cd8d3c11c4f098 /src/liballoc
parentdcc1d1463ac12c3ba341c658d8bbc7546422fb1e (diff)
parentc430fa8084277c9ee36b022dd028ed302b3f5afe (diff)
downloadrust-8a7d93bf6f5b1a699bafec6f59964a3962b2e927.tar.gz
rust-8a7d93bf6f5b1a699bafec6f59964a3962b2e927.zip
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
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/str.rs23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs
index c1252b219c4..f0c63a2eb55 100644
--- a/src/liballoc/str.rs
+++ b/src/liballoc/str.rs
@@ -390,16 +390,25 @@ impl str {
     /// # Examples
     ///
     /// ```
-    /// let mut v = String::from("🗻∈🌏");
-    ///
-    /// assert_eq!(Some("🗻"), v.get_mut(0..4).map(|v| &*v));
-    ///
-    /// // indices not on UTF-8 sequence boundaries
-    /// assert!(v.get_mut(1..).is_none());
-    /// assert!(v.get_mut(..8).is_none());
+    /// use std::ascii::AsciiExt;
     ///
+    /// let mut v = String::from("hello");
+    /// // correct length
+    /// assert!(v.get_mut(0..5).is_some());
     /// // out of bounds
     /// assert!(v.get_mut(..42).is_none());
+    /// assert_eq!(Some("he"), v.get_mut(0..2).map(|v| &*v));
+    ///
+    /// assert_eq!("hello", v);
+    /// {
+    ///     let s = v.get_mut(0..2);
+    ///     let s = s.map(|s| {
+    ///         s.make_ascii_uppercase();
+    ///         &*s
+    ///     });
+    ///     assert_eq!(Some("HE"), s);
+    /// }
+    /// assert_eq!("HEllo", v);
     /// ```
     #[stable(feature = "str_checked_slicing", since = "1.20.0")]
     #[inline]