diff --git a/src/generic.rs b/src/generic.rs index 523514c..3481922 100644 --- a/src/generic.rs +++ b/src/generic.rs @@ -68,11 +68,11 @@ impl<'a, T: Copy> IFlagAction for StoreConstAction<'a, T> { impl<'a, T: FromStr> IArgAction for StoreAction<'a, T> { fn parse_arg(&self, arg: &str) -> ParseResult { match FromStr::from_str(arg) { - Some(x) => { + Ok(x) => { **self.cell.borrow_mut() = x; return Parsed; } - None => { + Err(_) => { return Error(format!("Bad value {}", arg)); } } @@ -82,11 +82,11 @@ impl<'a, T: FromStr> IArgAction for StoreAction<'a, T> { impl<'a, T: FromStr> IArgAction for StoreOptionAction<'a, T> { fn parse_arg(&self, arg: &str) -> ParseResult { match FromStr::from_str(arg) { - Some(x) => { + Ok(x) => { **self.cell.borrow_mut() = Some(x); return Parsed; } - None => { + Err(_) => { return Error(format!("Bad value {}", arg)); } } @@ -98,10 +98,10 @@ impl<'a, T: FromStr + Clone> IArgsAction for ListAction<'a, T> { let mut result = box Vec::new(); for arg in args.iter() { match FromStr::from_str(*arg) { - Some(x) => { + Ok(x) => { result.push(x); } - None => { + Err(_) => { return Error(format!("Bad value {}", arg)); } } diff --git a/src/help.rs b/src/help.rs index 0e053e1..0fabd68 100644 --- a/src/help.rs +++ b/src/help.rs @@ -44,7 +44,11 @@ impl<'a> Iterator for WordsIter<'a> { } } } - for (idx, ch) in self.iter { + loop { + let (idx, ch) = match self.iter.next() { + None => break, + Some((idx, ch)) => ((idx, ch)), + }; match ch { ' ' | '\t' | '\r' | '\n' => { return Some(self.data.slice(word_start, idx)); diff --git a/src/test_enum.rs b/src/test_enum.rs index 5f263df..8edea9c 100644 --- a/src/test_enum.rs +++ b/src/test_enum.rs @@ -7,7 +7,7 @@ use test_parser::{check_ok,check_err}; use self::Greeting::{Hello, Hi, NoGreeting}; -#[derive(PartialEq, Eq, Show)] +#[derive(PartialEq, Eq, Debug)] enum Greeting { Hello, Hi, @@ -15,11 +15,12 @@ enum Greeting { } impl FromStr for Greeting { - fn from_str(src: &str) -> Option { + type Err = (); + fn from_str(src: &str) -> Result { return match src { - "hello" => Some(Hello), - "hi" => Some(Hi), - _ => None, + "hello" => Ok(Hello), + "hi" => Ok(Hi), + _ => Err(()), }; } } diff --git a/src/test_help.rs b/src/test_help.rs index 2ea44ce..9e230c7 100644 --- a/src/test_help.rs +++ b/src/test_help.rs @@ -22,9 +22,9 @@ fn test_empty() { #[test] fn test_options() { - let mut ap = ArgumentParser::new(); let mut val = 0; let mut val2 = 0; + let mut ap = ArgumentParser::new(); ap.set_description("Test program. The description of the program is ought to be very long, because we want to test how word wrapping works for it. So some more text would be ok for the test"); @@ -53,8 +53,8 @@ for the test\n" #[test] fn test_argument() { - let mut ap = ArgumentParser::new(); let mut val = 0; + let mut ap = ArgumentParser::new(); ap.set_description("Test program"); ap.refer(&mut val) .add_argument("value", box Store::, @@ -76,9 +76,9 @@ fn test_argument() { #[test] fn test_arguments() { - let mut ap = ArgumentParser::new(); let mut v1 = 0; let mut v2 = Vec::new(); + let mut ap = ArgumentParser::new(); ap.set_description("Test program"); ap.refer(&mut v1) .add_argument("v1", box Store::, @@ -104,9 +104,9 @@ fn test_arguments() { #[test] fn test_req_arguments() { - let mut ap = ArgumentParser::new(); let mut v1 = 0; let mut v2 = Vec::new(); + let mut ap = ArgumentParser::new(); ap.set_description("Test program"); ap.refer(&mut v1) .add_argument("v1", box Store::, @@ -134,8 +134,8 @@ fn test_req_arguments() { #[test] fn test_metavar() { - let mut ap = ArgumentParser::new(); let mut val2 = 0; + let mut ap = ArgumentParser::new(); ap.set_description("Test program."); ap.refer(&mut val2) .add_option(&["-L", "--long-option"], box Store::, diff --git a/src/test_usage.rs b/src/test_usage.rs index 9b5fd16..241b847 100644 --- a/src/test_usage.rs +++ b/src/test_usage.rs @@ -15,21 +15,23 @@ fn test_empty() { #[test] fn test_options() { - let mut ap = ArgumentParser::new(); let mut val = 0; - ap.refer(&mut val) - .add_option(&["--value"], box Store::, - "Set integer value"); let mut buf = MemWriter::new(); - assert_eq!(ap.print_usage("./argparse_test", &mut buf), Ok(())); + { + let mut ap = ArgumentParser::new(); + ap.refer(&mut val) + .add_option(&["--value"], box Store::, + "Set integer value"); + assert_eq!(ap.print_usage("./argparse_test", &mut buf), Ok(())); + } assert_eq!("Usage:\n ./argparse_test [OPTIONS]\n", from_utf8(buf.into_inner().as_slice()).unwrap()); } #[test] fn test_argument() { - let mut ap = ArgumentParser::new(); let mut val = 0; + let mut ap = ArgumentParser::new(); ap.refer(&mut val) .add_argument("value", box Store::, "Integer value"); @@ -41,9 +43,9 @@ fn test_argument() { #[test] fn test_arguments() { - let mut ap = ArgumentParser::new(); let mut v1 = 0; let mut v2 = Vec::new(); + let mut ap = ArgumentParser::new(); ap.refer(&mut v1) .add_argument("v1", box Store::, "Integer value 1"); diff --git a/vagga.yaml b/vagga.yaml index ce2b3a0..ad2bf44 100644 --- a/vagga.yaml +++ b/vagga.yaml @@ -5,7 +5,7 @@ containers: - !Ubuntu trusty - !Install [make, gcc] - !TarInstall - url: http://static.rust-lang.org/dist/rust-1.0.0-alpha-x86_64-unknown-linux-gnu.tar.gz + url: http://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.gz script: ./install.sh --prefix=/usr volumes: /tmp: !Tmpfs { size: 100Mi }