11#![ allow( clippy:: needless_return) ]
2+ #![ allow( clippy:: items_after_test_module) ]
23//! # Lambda Args
34//! Lambda Args is a simple argument parser for Rust. It is designed to be
45//! simple to use and primarily for use in lambda command line applications.
@@ -72,42 +73,42 @@ pub enum ArgumentValue {
7273 String ( String ) ,
7374}
7475
75- impl Into < String > for ArgumentValue {
76- fn into ( self ) -> String {
77- return match self {
76+ impl From < ArgumentValue > for String {
77+ fn from ( value : ArgumentValue ) -> Self {
78+ return match value {
7879 ArgumentValue :: String ( val) => val,
79- _ => panic ! ( "Cannot convert {:?} into a String." , self ) ,
80+ other => panic ! ( "Cannot convert {:?} into a String." , other ) ,
8081 } ;
8182 }
8283}
8384
84- impl Into < i64 > for ArgumentValue {
85- fn into ( self ) -> i64 {
86- return match self {
85+ impl From < ArgumentValue > for i64 {
86+ fn from ( value : ArgumentValue ) -> Self {
87+ return match value {
8788 ArgumentValue :: Integer ( val) => val,
8889 ArgumentValue :: Float ( val) => val as i64 ,
8990 ArgumentValue :: Double ( val) => val as i64 ,
90- _ => panic ! ( "Cannot convert {:?} into an i64" , self ) ,
91+ other => panic ! ( "Cannot convert {:?} into an i64" , other ) ,
9192 } ;
9293 }
9394}
9495
95- impl Into < f32 > for ArgumentValue {
96- fn into ( self ) -> f32 {
97- return match self {
96+ impl From < ArgumentValue > for f32 {
97+ fn from ( value : ArgumentValue ) -> Self {
98+ return match value {
9899 ArgumentValue :: Float ( val) => val,
99- _ => panic ! ( "Cannot convert {:?} into a f32" , self ) ,
100+ other => panic ! ( "Cannot convert {:?} into a f32" , other ) ,
100101 } ;
101102 }
102103}
103104
104- impl Into < f64 > for ArgumentValue {
105- fn into ( self ) -> f64 {
106- return match self {
105+ impl From < ArgumentValue > for f64 {
106+ fn from ( value : ArgumentValue ) -> Self {
107+ return match value {
107108 ArgumentValue :: Double ( val) => val,
108109 ArgumentValue :: Float ( val) => val as f64 ,
109110 ArgumentValue :: Integer ( val) => val as f64 ,
110- _ => panic ! ( "Cannot convert {:?} into a f64" , self ) ,
111+ other => panic ! ( "Cannot convert {:?} into a f64" , other ) ,
111112 } ;
112113 }
113114}
@@ -194,7 +195,7 @@ impl Argument {
194195 }
195196
196197 pub fn arg_type ( & self ) -> ArgumentType {
197- return self . arg_type . clone ( ) ;
198+ return self . arg_type ;
198199 }
199200
200201 /// Canonical name used for matching and display (e.g., `--output`).
@@ -406,11 +407,12 @@ impl ArgumentParser {
406407 format ! ( " (aliases: {})" , arg. aliases( ) . join( ", " ) )
407408 } ;
408409 out. push_str ( & format ! (
409- " {}{}\n {}{}{}\n " ,
410+ " {}{}\n {}{}{}{} \n " ,
410411 arg. name( ) ,
411412 sep,
412413 desc,
413- format!( "{}{}" , req, def) ,
414+ req,
415+ def,
414416 aliases
415417 ) ) ;
416418 }
@@ -583,13 +585,13 @@ impl ArgumentParser {
583585 if matches ! ( pre. 0 . arg_type( ) , ArgumentType :: Count ) {
584586 let index = pre. 2 ;
585587 let current = match & parsed_arguments[ index] . value {
586- ArgumentValue :: Integer ( v) => * v as i64 ,
588+ ArgumentValue :: Integer ( v) => * v,
587589 _ => 0 ,
588590 } ;
589591 let found = self . args . get_mut ( & canon) . unwrap ( ) ;
590592 parsed_arguments[ index] = ParsedArgument :: new (
591593 found. 0 . name . as_str ( ) ,
592- ArgumentValue :: Integer ( ( current + 1 ) as i64 ) ,
594+ ArgumentValue :: Integer ( current + 1 ) ,
593595 ) ;
594596 found. 1 = true ;
595597 } else if matches ! ( pre. 0 . arg_type( ) , ArgumentType :: Boolean ) {
@@ -619,7 +621,7 @@ impl ArgumentParser {
619621 return Err ( ArgsError :: UnknownArgument ( msg) ) ;
620622 } ;
621623 let pre = self . args . get ( & canon_name) . unwrap ( ) ;
622- if pre. 1 == true {
624+ if pre. 1 {
623625 return Err ( ArgsError :: DuplicateArgument ( pre. 0 . name . clone ( ) ) ) ;
624626 }
625627 // Boolean flags can be set by presence alone
@@ -636,12 +638,12 @@ impl ArgumentParser {
636638 let index = pre. 2 ;
637639 let found = self . args . get_mut ( & canon_name) . unwrap ( ) ;
638640 let current = match & parsed_arguments[ index] . value {
639- ArgumentValue :: Integer ( v) => * v as i64 ,
641+ ArgumentValue :: Integer ( v) => * v,
640642 _ => 0 ,
641643 } ;
642644 parsed_arguments[ index] = ParsedArgument :: new (
643645 found. 0 . name . as_str ( ) ,
644- ArgumentValue :: Integer ( ( current + 1 ) as i64 ) ,
646+ ArgumentValue :: Integer ( current + 1 ) ,
645647 ) ;
646648 found. 1 = true ;
647649 continue ;
@@ -1022,12 +1024,12 @@ mod tests {
10221024 Argument :: new ( "--verbose" ) . with_type ( ArgumentType :: Boolean ) ,
10231025 ) ;
10241026 let p = parser. parse ( & argv ( & [ "--verbose" ] ) ) . unwrap ( ) ;
1025- assert_eq ! ( p. get_bool( "--verbose" ) . unwrap( ) , true ) ;
1027+ assert ! ( p. get_bool( "--verbose" ) . unwrap( ) ) ;
10261028 let parser2 = ArgumentParser :: new ( "app" ) . with_argument (
10271029 Argument :: new ( "--verbose" ) . with_type ( ArgumentType :: Boolean ) ,
10281030 ) ;
10291031 let p2 = parser2. parse ( & argv ( & [ "--no-verbose" ] ) ) . unwrap ( ) ;
1030- assert_eq ! ( p2. get_bool( "--verbose" ) . unwrap( ) , false ) ;
1032+ assert ! ( ! p2. get_bool( "--verbose" ) . unwrap( ) ) ;
10311033 }
10321034
10331035 #[ test]
@@ -1279,12 +1281,12 @@ impl ArgumentParser {
12791281
12801282 fn assign_next_positional (
12811283 & mut self ,
1282- out : & mut Vec < ParsedArgument > ,
1284+ out : & mut [ ParsedArgument ] ,
12831285 value : & str ,
12841286 ) -> Result < ( ) , ArgsError > {
12851287 for pname in self . positionals . clone ( ) {
12861288 if let Some ( entry) = self . args . get_mut ( & pname) {
1287- if entry. 1 == false {
1289+ if ! entry. 1 {
12881290 let parsed = parse_value ( & entry. 0 , value) ?;
12891291 let idx = entry. 2 ;
12901292 out[ idx] = ParsedArgument :: new ( entry. 0 . name . as_str ( ) , parsed) ;
@@ -1300,7 +1302,7 @@ impl ArgumentParser {
13001302 } )
13011303 }
13021304
1303- fn get_present ( & self , out : & Vec < ParsedArgument > , name : & str ) -> bool {
1305+ fn get_present ( & self , out : & [ ParsedArgument ] , name : & str ) -> bool {
13041306 let canon = if self . args . contains_key ( name) {
13051307 name. to_string ( )
13061308 } else if let Some ( n) = self . aliases . get ( name) {
0 commit comments