-
Notifications
You must be signed in to change notification settings - Fork 46
/
fib_with_argparse.rs
64 lines (59 loc) · 1.63 KB
/
fib_with_argparse.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! ```cargo
//! [package]
//! edition = "2021"
//! [dependencies]
//! anyhow = "*"
//! structopt = "*"
//! ```
#![allow(clippy::assertions_on_constants)]
#![allow(clippy::bool_comparison)]
#![allow(clippy::collapsible_else_if)]
#![allow(clippy::comparison_to_empty)]
#![allow(clippy::double_parens)] // https://github.com/adsharma/py2many/issues/17
#![allow(clippy::eq_op)]
#![allow(clippy::let_with_type_underscore)]
#![allow(clippy::map_identity)]
#![allow(clippy::needless_return)]
#![allow(clippy::nonminimal_bool)]
#![allow(clippy::partialeq_to_none)]
#![allow(clippy::print_literal)]
#![allow(clippy::ptr_arg)]
#![allow(clippy::redundant_static_lifetimes)] // https://github.com/adsharma/py2many/issues/266
#![allow(clippy::unnecessary_cast)]
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::useless_vec)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(unused_imports)]
#![allow(unused_mut)]
#![allow(unused_parens)]
extern crate anyhow;
extern crate structopt;
use anyhow::Result;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "fib_with_argparse", about = "Placeholder")]
struct Options {
#[structopt(short, long)]
pub v: bool,
#[structopt(short, long, default_value = "0")]
pub n: i32,
}
pub fn fib(i: i32) -> i32 {
if i == 0 || i == 1 {
return 1;
}
return (fib((i - 1)) + fib((i - 2)));
}
pub fn main() -> Result<()> {
let mut args = Options::from_args();
if args.v {
println!("{}", "args.v is true");
}
if (args.n as i32) == 0 {
args.n = 5;
}
println!("{}", fib(args.n));
Ok(())
}