about summary refs log tree commit diff
path: root/src/liballoc/lib.rs
diff options
context:
space:
mode:
authorJohn Ford <jhford@users.noreply.github.com>2017-11-08 22:40:35 +0100
committerGitHub <noreply@github.com>2017-11-08 22:40:35 +0100
commitcd32aff3fcdea295ed147bc16eb9299fe9876c0f (patch)
tree84b456613da2f60a278c3a3bfc319754bbb602ad /src/liballoc/lib.rs
parent7ca430df713ad1697a9d27eb4ae0f49c8563eed4 (diff)
downloadrust-cd32aff3fcdea295ed147bc16eb9299fe9876c0f.tar.gz
rust-cd32aff3fcdea295ed147bc16eb9299fe9876c0f.zip
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/lib.rs')
0 files changed, 0 insertions, 0 deletions