Przeglądaj źródła

Deleted commented code. Moved functions. Rustfmt.

Joshua Rutschmann 8 lat temu
rodzic
commit
0ee735539d
2 zmienionych plików z 51 dodań i 68 usunięć
  1. 51
    0
      hw2/task2/src/lib.rs
  2. 0
    68
      hw2/task2/src/main.rs

+ 51
- 0
hw2/task2/src/lib.rs Wyświetl plik

@@ -15,6 +15,57 @@ pub fn run(conf: &Config) -> i32 {
15 15
     count
16 16
 }
17 17
 
18
+/// Parses relevant arguments, returning the filled Config in Result
19
+///
20
+///
21
+/// This function will parse the relevant arguments from the
22
+/// given <Strings>.
23
+/// Returns Config or Error Message in Result
24
+#[allow(dead_code)]
25
+fn parse_arguments(args: &Vec<String>) -> Result<Config, String> {
26
+
27
+    if args.len() < 3 {
28
+        return Err("not ennugh parameters".to_string());
29
+    }
30
+
31
+    match args[1].chars().nth(0) {
32
+        Some(value) => {
33
+            Ok(Config {
34
+                search: value,
35
+                line: args[2].clone(),
36
+            })
37
+        }
38
+        None => Err("char mismatch".to_string()),
39
+    }
40
+}
41
+
42
+/// Parses relevant arguments, returning the filled Config
43
+///
44
+///
45
+/// This function will parse the relevant arguments from the
46
+/// given <Strings>.
47
+/// Returns Config
48
+#[allow(dead_code)]
49
+fn parse_arguments_simple(args: &Vec<String>) -> Config {
50
+    Config {
51
+        search: args[1].chars().nth(0).unwrap(),
52
+        line: args[2].clone(),
53
+    }
54
+}
55
+
56
+/// Prints elements of Vec
57
+///
58
+///
59
+/// This function will print all elements of Vec with "args found: <elem>" in
60
+/// each line
61
+///
62
+/// Returns nothing
63
+#[allow(dead_code)]
64
+fn print_arguments(args: &Vec<String>) {
65
+    for s in args {
66
+        println!("args found: {}", s);
67
+    }
68
+}
18 69
 
19 70
 impl Config {
20 71
     pub fn new(args: &Vec<String>) -> Result<Config, &str> {

+ 0
- 68
hw2/task2/src/main.rs Wyświetl plik

@@ -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
-}

Ładowanie…
Anuluj
Zapisz