Updated examples with better example

Now we'll encourage users to create an actual vector, instead of an array slice.
It's better form to do so, anyways.
This commit is contained in:
Zach Dziura 2015-05-25 11:14:13 -04:00
parent 29077d64d6
commit 297aaa0ad3
2 changed files with 10 additions and 10 deletions

View file

@ -39,10 +39,10 @@ extern crate pirate;
Usage Usage
----- -----
Using Pirate is simple. First, create an array slice defining all of the valid opts that your Using Pirate is simple. First, create a vector defining all of the valid opts that your
program accepts: program accepts:
`let opts = &["o:", "l/long", ":arg"];` `let opts = vec!["o:", "l/long", ":arg"];`
Opts are defined in a specific format: Opts are defined in a specific format:
@ -53,15 +53,15 @@ Opts are defined in a specific format:
* All other opts are defined normally, e.g. `"l"` is an opt in short form, `"long"` is an opt in * All other opts are defined normally, e.g. `"l"` is an opt in short form, `"long"` is an opt in
long form. long form.
Next, call the `pirate::parse()` function, passing in the environment arguments along with the slice Next, call the `pirate::parse()` function, passing in the environment arguments along with a reference
of opts that you defined: to the opts that you defined:
`let matches = pirate::parse(env::args(), opts);` `let matches = pirate::parse(env::args(), &opts);`
Now, handle any errors that may have arisen from parsing: Now, handle any errors that may have arisen from parsing:
``` ```
let matches: Matches = match pirate::parse(env::args(), opts) { let matches: Matches = match pirate::parse(env::args(), &opts) {
Err(ref e) => { Err(ref e) => {
println!("Error: {}", e); println!("Error: {}", e);
help(); help();
@ -97,9 +97,9 @@ use pirate::Matches;
fn main() { fn main() {
let opts = &["n:", "b/boop", ":input"]; let opts = vec!["n:", "b/boop", ":input"];
let matches: Matches = match pirate::parse(env::args(), opts) { let matches: Matches = match pirate::parse(env::args(), &opts) {
Err(ref e) => { Err(ref e) => {
println!("Error: {}", e); println!("Error: {}", e);
help(); help();

View file

@ -5,9 +5,9 @@ use std::env;
use pirate::Matches; use pirate::Matches;
fn main() { fn main() {
let opts = &["n:", "b/boop", ":input"]; let opts = vec!["n:", "b/boop", ":input"];
let matches: Matches = match pirate::parse(env::args(), opts) { let matches: Matches = match pirate::parse(env::args(), &opts) {
Err(ref e) => { Err(ref e) => {
println!("Error: {}", e); println!("Error: {}", e);
help(); help();