about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-08-04 08:21:28 -0400
committerCorey Farwell <coreyf@rwell.org>2017-08-04 08:21:28 -0400
commitea6a6571758229382d3fcb3fcc9e273c9b854345 (patch)
treede8f628b4d955f839d51576137bf34afba94527b /src/liballoc
parentc523b3f95498cf35a2f1a6bb8c071394ca4a6143 (diff)
downloadrust-ea6a6571758229382d3fcb3fcc9e273c9b854345.tar.gz
rust-ea6a6571758229382d3fcb3fcc9e273c9b854345.zip
Indicate why str::{get,get_mut} examples return None.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/str.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs
index 4df13c509a8..bbdc36b8737 100644
--- a/src/liballoc/str.rs
+++ b/src/liballoc/str.rs
@@ -328,11 +328,16 @@ impl str {
     /// # Examples
     ///
     /// ```
-    /// let v = "🗻∈🌏";
-    /// assert_eq!(Some("🗻"), v.get(0..4));
-    /// assert!(v.get(1..).is_none());
-    /// assert!(v.get(..8).is_none());
-    /// assert!(v.get(..42).is_none());
+    /// let mut v = String::from("🗻∈🌏");
+    ///
+    /// assert_eq!(Some("🗻"), v.get(0..4);
+    ///
+    /// // indices not on UTF-8 sequence boundaries
+    /// assert!(v.get_mut(1..).is_none());
+    /// assert!(v.get_mut(..8).is_none());
+    ///
+    /// // out of bounds
+    /// assert!(v.get_mut(..42).is_none());
     /// ```
     #[stable(feature = "str_checked_slicing", since = "1.20.0")]
     #[inline]
@@ -351,9 +356,14 @@ impl str {
     ///
     /// ```
     /// 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());
+    ///
+    /// // out of bounds
     /// assert!(v.get_mut(..42).is_none());
     /// ```
     #[stable(feature = "str_checked_slicing", since = "1.20.0")]