From 297aaa0ad3cbf7b33919060d09632772a4d53bff Mon Sep 17 00:00:00 2001 From: Zach Dziura Date: Mon, 25 May 2015 11:14:13 -0400 Subject: [PATCH] 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. --- README.md | 16 ++++++++-------- tests/main.rs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7025b63..c8136d6 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,10 @@ extern crate pirate; 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: -`let opts = &["o:", "l/long", ":arg"];` +`let opts = vec!["o:", "l/long", ":arg"];` 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 long form. -Next, call the `pirate::parse()` function, passing in the environment arguments along with the slice -of opts that you defined: +Next, call the `pirate::parse()` function, passing in the environment arguments along with a reference +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: ``` -let matches: Matches = match pirate::parse(env::args(), opts) { +let matches: Matches = match pirate::parse(env::args(), &opts) { Err(ref e) => { println!("Error: {}", e); help(); @@ -97,9 +97,9 @@ use pirate::Matches; 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) => { println!("Error: {}", e); help(); diff --git a/tests/main.rs b/tests/main.rs index ba8dbc0..23254a0 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -5,9 +5,9 @@ use std::env; use pirate::Matches; 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) => { println!("Error: {}", e); help();