Skip to content

Commit ea6a657

Browse files
committed
Indicate why str::{get,get_mut} examples return None.
1 parent c523b3f commit ea6a657

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/liballoc/str.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,16 @@ impl str {
328328
/// # Examples
329329
///
330330
/// ```
331-
/// let v = "🗻∈🌏";
332-
/// assert_eq!(Some("🗻"), v.get(0..4));
333-
/// assert!(v.get(1..).is_none());
334-
/// assert!(v.get(..8).is_none());
335-
/// assert!(v.get(..42).is_none());
331+
/// let mut v = String::from("🗻∈🌏");
332+
///
333+
/// assert_eq!(Some("🗻"), v.get(0..4);
334+
///
335+
/// // indices not on UTF-8 sequence boundaries
336+
/// assert!(v.get_mut(1..).is_none());
337+
/// assert!(v.get_mut(..8).is_none());
338+
///
339+
/// // out of bounds
340+
/// assert!(v.get_mut(..42).is_none());
336341
/// ```
337342
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
338343
#[inline]
@@ -351,9 +356,14 @@ impl str {
351356
///
352357
/// ```
353358
/// let mut v = String::from("🗻∈🌏");
359+
///
354360
/// assert_eq!(Some("🗻"), v.get_mut(0..4).map(|v| &*v));
361+
///
362+
/// // indices not on UTF-8 sequence boundaries
355363
/// assert!(v.get_mut(1..).is_none());
356364
/// assert!(v.get_mut(..8).is_none());
365+
///
366+
/// // out of bounds
357367
/// assert!(v.get_mut(..42).is_none());
358368
/// ```
359369
#[stable(feature = "str_checked_slicing", since = "1.20.0")]

0 commit comments

Comments
 (0)