Skip to content

Commit cd32aff

Browse files
authored
get() example should use get() not get_mut()
I'm really new to Rust, this is the first thing I've ever actually pushed to github in a rust project, so please double check that it's correct. I noticed that the in-doc example for the string's get() function was referring to get_mut(). Looks like a copy/paste issue. ```rust fn main() { let v = String::from("🗻∈🌏"); assert_eq!(Some("🗻"), v.get(0..4)); // indices not on UTF-8 sequence boundaries assert!(v.get(1..).is_none()); assert!(v.get(..8).is_none()); // out of bounds assert!(v.get(..42).is_none()); } ``` results in: ``` jhford-work:~/rust/redish $ cat get-example.rs fn main() { let v = String::from("🗻∈🌏"); assert_eq!(Some("🗻"), v.get(0..4)); // indices not on UTF-8 sequence boundaries assert!(v.get(1..).is_none()); assert!(v.get(..8).is_none()); // out of bounds assert!(v.get(..42).is_none()); } jhford-work:~/rust/redish $ rustc get-example.rs jhford-work:~/rust/redish $ ./get-example ; echo $? 0 ``` I did not build an entire rust toolchain as I'm not totally sure how to do that.
1 parent 7ca430d commit cd32aff

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/liballoc/str.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,16 @@ impl str {
363363
/// # Examples
364364
///
365365
/// ```
366-
/// let mut v = String::from("🗻∈🌏");
366+
/// let v = String::from("🗻∈🌏");
367367
///
368368
/// assert_eq!(Some("🗻"), v.get(0..4));
369369
///
370370
/// // indices not on UTF-8 sequence boundaries
371-
/// assert!(v.get_mut(1..).is_none());
372-
/// assert!(v.get_mut(..8).is_none());
371+
/// assert!(v.get(1..).is_none());
372+
/// assert!(v.get(..8).is_none());
373373
///
374374
/// // out of bounds
375-
/// assert!(v.get_mut(..42).is_none());
375+
/// assert!(v.get(..42).is_none());
376376
/// ```
377377
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
378378
#[inline]

0 commit comments

Comments
 (0)