Skip to content

Commit 58618fb

Browse files
committed
auto merge of #5308 : wanderview/rust/std-getopts-rustdoc-fix, r=luqmana
There were three issues effecting the example in the getopts rustdoc: 1. The blockquote was incorrectly formatted. Fixed by switching to using an explicit markdown code section with ```. 2. The `fail fail_str(f)` would not compile. Fixed by using `fail!()` instead of `fail`. 3. The line `matches.free[0]` produced a compile error about moving from an immutable vector. Fix by using `copy`.
2 parents 1d8596d + 13e5859 commit 58618fb

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/libstd/getopts.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -29,8 +29,10 @@
2929
* The following example shows simple command line parsing for an application
3030
* that requires an input file to be specified, accepts an optional output
3131
* file name following -o, and accepts both -h and --help as optional flags.
32-
* extern mod std;
33-
* use std::getopts::*;
32+
*
33+
* ```
34+
* extern mod std;
35+
* use std::getopts::*;
3436
*
3537
* fn do_work(in: &str, out: Option<~str>) {
3638
* io::println(in);
@@ -58,21 +60,22 @@
5860
* ];
5961
* let matches = match getopts(vec::tail(args), opts) {
6062
* result::Ok(m) => { m }
61-
* result::Err(f) => { fail fail_str(f) }
63+
* result::Err(f) => { fail!(fail_str(f)) }
6264
* };
6365
* if opt_present(&matches, "h") || opt_present(&matches, "help") {
6466
* print_usage(program, opts);
6567
* return;
6668
* }
6769
* let output = opt_maybe_str(&matches, "o");
6870
* let input: &str = if !matches.free.is_empty() {
69-
* matches.free[0]
71+
* copy matches.free[0]
7072
* } else {
7173
* print_usage(program, opts);
7274
* return;
7375
* };
7476
* do_work(input, output);
7577
* }
78+
* ```
7679
*/
7780

7881
use core::cmp::Eq;

0 commit comments

Comments
 (0)