[libstd] getopts, now with fewer copies
Change the opt_ functions in getopts to take a reference to a Matches, instead of taking a Matches by-value, as suggested in
This commit is contained in:
parent
e454a47bf2
commit
f74fe894fc
10 changed files with 68 additions and 53 deletions
|
|
@ -53,7 +53,7 @@ fn parse_opts(argv: ~[~str]) -> config {
|
|||
let opt_args = vec::slice(argv, 1u, vec::len(argv));
|
||||
|
||||
match getopts::getopts(opt_args, opts) {
|
||||
Ok(m) => { return {stress: getopts::opt_present(m, ~"stress")} }
|
||||
Ok(ref m) => { return {stress: getopts::opt_present(m, ~"stress")} }
|
||||
Err(_) => { fail; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
src/test/run-pass/getopts_ref.rs
Normal file
15
src/test/run-pass/getopts_ref.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
extern mod std;
|
||||
|
||||
use std::getopts::*;
|
||||
|
||||
fn main() {
|
||||
let args = ~[];
|
||||
let opts = ~[optopt(~"b")];
|
||||
|
||||
match getopts(args, opts) {
|
||||
result::Ok(ref m) =>
|
||||
assert !opt_present(m, "b"),
|
||||
result::Err(f) => fail fail_str(f)
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue