Skip to content

Commit

Permalink
Fix formatting and errors in std::getopts example.
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
wanderview committed Mar 10, 2013
1 parent 267f6c2 commit a363862
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/libstd/getopts.rs
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2011-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -29,8 +29,10 @@
* The following example shows simple command line parsing for an application
* that requires an input file to be specified, accepts an optional output
* file name following -o, and accepts both -h and --help as optional flags.
* extern mod std;
* use std::getopts::*;
*
* ```
* extern mod std;
* use std::getopts::*;
*
* fn do_work(in: &str, out: Option<~str>) {
* io::println(in);
Expand Down Expand Up @@ -58,21 +60,22 @@
* ];
* let matches = match getopts(vec::tail(args), opts) {
* result::Ok(m) => { m }
* result::Err(f) => { fail fail_str(f) }
* result::Err(f) => { fail!(fail_str(f)) }
* };
* if opt_present(&matches, "h") || opt_present(&matches, "help") {
* print_usage(program, opts);
* return;
* }
* let output = opt_maybe_str(&matches, "o");
* let input: &str = if !matches.free.is_empty() {
* matches.free[0]
* copy matches.free[0]
* } else {
* print_usage(program, opts);
* return;
* };
* do_work(input, output);
* }
* ```
*/

use core::cmp::Eq;
Expand Down

4 comments on commit a363862

@bors
Copy link
Contributor

@bors bors commented on a363862 Mar 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at wanderview@a363862

@bors
Copy link
Contributor

@bors bors commented on a363862 Mar 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging wanderview/rust/std-getopts-rustdoc-fix = a363862 into auto

@bors
Copy link
Contributor

@bors bors commented on a363862 Mar 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanderview/rust/std-getopts-rustdoc-fix = a363862 merged ok, testing candidate = 5babc316

@bors
Copy link
Contributor

@bors bors commented on a363862 Mar 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.