Browse Source

hw2/task2 complete, but tests cannot see function *run()*

Joshua Rutschmann 8 years ago
parent
commit
2994da0470
1 changed files with 24 additions and 0 deletions
  1. 24
    0
      hw2/task2/src/lib.rs

+ 24
- 0
hw2/task2/src/lib.rs View File

1
+/// a struct to hold all of our configuration
2
+#[derive(Debug, PartialEq)]
3
+pub struct Config {
4
+    pub search: char,
5
+    pub line: String,
6
+}
7
+
8
+impl Config {
9
+    pub fn new(args: &Vec<String>) -> Result<Config, &str> {
10
+        if args.len() < 2 {
11
+            return Err("not ennugh parameters");
12
+        }
13
+
14
+        match args[1].chars().nth(0) {
15
+            Some(value) => {
16
+                Ok(Config {
17
+                    search: value,
18
+                    line: args[2].clone(),
19
+                })
20
+            }
21
+            None => Err("char mismatch"),
22
+        }
23
+    }
24
+}

Loading…
Cancel
Save