|
|
@@ -6,10 +6,6 @@ extern crate task2;
|
|
6
|
6
|
fn main() {
|
|
7
|
7
|
let args = env::args().collect();
|
|
8
|
8
|
|
|
9
|
|
- //print_arguments(&args);
|
|
10
|
|
- //let conf = parse_arguments_simple(&args);
|
|
11
|
|
- //let res = parse_arguments(&args);
|
|
12
|
|
-
|
|
13
|
9
|
let res = Config::new(&args);
|
|
14
|
10
|
match res {
|
|
15
|
11
|
Ok(conf) => {
|
|
|
@@ -30,67 +26,3 @@ fn main() {
|
|
30
|
26
|
|
|
31
|
27
|
|
|
32
|
28
|
}
|
|
33
|
|
-
|
|
34
|
|
-/*
|
|
35
|
|
-pub fn run(conf: &Config) -> i32 {
|
|
36
|
|
- let mut count = 0;
|
|
37
|
|
- for c in conf.line.chars() {
|
|
38
|
|
- if c == conf.search {
|
|
39
|
|
- count = count + 1;
|
|
40
|
|
- }
|
|
41
|
|
- }
|
|
42
|
|
- count
|
|
43
|
|
-}
|
|
44
|
|
-*/
|
|
45
|
|
-
|
|
46
|
|
-/// Parses relevant arguments, returning the filled Config in Result
|
|
47
|
|
-///
|
|
48
|
|
-///
|
|
49
|
|
-/// This function will parse the relevant arguments from the
|
|
50
|
|
-/// given <Strings>.
|
|
51
|
|
-/// Returns Config or Error Message in Result
|
|
52
|
|
-#[allow(dead_code)]
|
|
53
|
|
-fn parse_arguments(args: &Vec<String>) -> Result<Config, String> {
|
|
54
|
|
-
|
|
55
|
|
- if args.len() < 3 {
|
|
56
|
|
- return Err("not ennugh parameters".to_string());
|
|
57
|
|
- }
|
|
58
|
|
-
|
|
59
|
|
- match args[1].chars().nth(0) {
|
|
60
|
|
- Some(value) => {
|
|
61
|
|
- Ok(Config {
|
|
62
|
|
- search: value,
|
|
63
|
|
- line: args[2].clone(),
|
|
64
|
|
- })
|
|
65
|
|
- }
|
|
66
|
|
- None => Err("char mismatch".to_string()),
|
|
67
|
|
- }
|
|
68
|
|
-}
|
|
69
|
|
-
|
|
70
|
|
-/// Parses relevant arguments, returning the filled Config
|
|
71
|
|
-///
|
|
72
|
|
-///
|
|
73
|
|
-/// This function will parse the relevant arguments from the
|
|
74
|
|
-/// given <Strings>.
|
|
75
|
|
-/// Returns Config
|
|
76
|
|
-#[allow(dead_code)]
|
|
77
|
|
-fn parse_arguments_simple(args: &Vec<String>) -> Config {
|
|
78
|
|
- Config {
|
|
79
|
|
- search: args[1].chars().nth(0).unwrap(),
|
|
80
|
|
- line: args[2].clone(),
|
|
81
|
|
- }
|
|
82
|
|
-}
|
|
83
|
|
-
|
|
84
|
|
-/// Prints elements of Vec
|
|
85
|
|
-///
|
|
86
|
|
-///
|
|
87
|
|
-/// This function will print all elements of Vec with "args found: <elem>" in
|
|
88
|
|
-/// each line
|
|
89
|
|
-///
|
|
90
|
|
-/// Returns nothing
|
|
91
|
|
-#[allow(dead_code)]
|
|
92
|
|
-fn print_arguments(args: &Vec<String>) {
|
|
93
|
|
- for s in args {
|
|
94
|
|
- println!("args found: {}", s);
|
|
95
|
|
- }
|
|
96
|
|
-}
|