diff options
| author | bors <bors@rust-lang.org> | 2013-10-12 20:16:19 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-10-12 20:16:19 -0700 |
| commit | 0bad7e1a37c21668ff4f4d4f4b629218b9f47538 (patch) | |
| tree | 3e64ccb840e13219ad12fa54cf02fe0d198186da /src/rt/sync/rust_thread.cpp | |
| parent | c6e3501da14784cd2401dded3b53f3ce3405b4ec (diff) | |
| parent | 21b24e148bd350c6f4945c35a7a30268ccf7d3cb (diff) | |
| download | rust-0bad7e1a37c21668ff4f4d4f4b629218b9f47538.tar.gz rust-0bad7e1a37c21668ff4f4d4f4b629218b9f47538.zip | |
auto merge of #9608 : hmarr/rust/vec-get-opt, r=huonw
This adds `get_opt` to `std::vec`, which looks up an item by index and returns an `Option`. If the given index is out of range, `None` will be returned, otherwise a `Some`-wrapped item will be returned.
Example use case:
```rust
use std::os;
fn say_hello(name: &str) {
println(fmt!("Hello, %s", name));
}
fn main(){
// Try to get the first cmd line arg, but default to "World"
let args = os::args();
let default = ~"World";
say_hello(*args.get_opt(1).unwrap_or(&default));
}
```
If there's an existing way of implementing this pattern that's cleaner, I'll happily close this. I'm also open to naming suggestions (`index_opt`?)
Diffstat (limited to 'src/rt/sync/rust_thread.cpp')
0 files changed, 0 insertions, 0 deletions
