diff options
| author | kennytm <kennytm@gmail.com> | 2017-11-10 17:07:08 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-10 17:07:08 +0800 |
| commit | e26bcbe4d4377fd663a765a8d2c337b79c64c988 (patch) | |
| tree | 156fb9d2366133b17e0deeaa4b5b63538e150184 /src/liballoc | |
| parent | 91cdb0f9bd819584a5cbd0edaeb8e994b6c1f0af (diff) | |
| parent | cd32aff3fcdea295ed147bc16eb9299fe9876c0f (diff) | |
| download | rust-e26bcbe4d4377fd663a765a8d2c337b79c64c988.tar.gz rust-e26bcbe4d4377fd663a765a8d2c337b79c64c988.zip | |
Rollup merge of #45878 - jhford:use-get-in-get-example, r=kennytm
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.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/str.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 5f0b4088fc0..a167b2e57c0 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -363,16 +363,16 @@ impl str { /// # Examples /// /// ``` - /// let mut v = String::from("🗻∈🌏"); + /// let 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()); + /// assert!(v.get(1..).is_none()); + /// assert!(v.get(..8).is_none()); /// /// // out of bounds - /// assert!(v.get_mut(..42).is_none()); + /// assert!(v.get(..42).is_none()); /// ``` #[stable(feature = "str_checked_slicing", since = "1.20.0")] #[inline] |
