From 3563377a5e7ca6f8b86795c9d3681df2f23902cc Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 17 May 2016 11:39:24 -0600 Subject: [PATCH] Updated `env::args().collect()` to output a Vec It seems `collect` defaults to collecting into an array which doesn't work with a collection of `String`s because `String`s vary in size and their size cannot be known at compile time. To work around this I collect the args into a `Vec` instead and pass that in. Also I think the first call to `matches` was missing an `&` on the `args` parameter. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d036e64..5cd760f 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ let vars: Vars = match pirate::vars("program-name", &options) { Next, call the `pirate::matches()` function, passing in a vector of the program's environment arguments, along with a mutable reference to the `Vars` struct that you previously defined: ```rust -let matches: Matches = match pirate::matches(env::args().collect(), - &mut vars) { +let args: Vec = env::args().collect(); +let matches: Matches = match pirate::matches(&args, &mut vars) { Ok(m) => m, Err(why) => { println!("Error: {}", why); @@ -90,8 +90,8 @@ Something to remember when using the `get()` function: by default, the `pirate:: ```rust let options = vec!["l/long#An example opt"]; let vars = pirate::vars("program-name", &options); -let matches = pirate::matches(&env::args().collect(), - &mut vars).unwrap(); +let args: Vec = env::args().collect(); +let matches = pirate::matches(&args, &mut vars).unwrap(); let short = matches.get("l").unwrap(); // Error! This won't work! let long = matches.get("long").unwrap(); // Success!