ソースを参照

Added main.rs

Lorenz Bung 8年前
コミット
7cdee6f4bb
3個のファイルの変更17行の追加16行の削除
  1. 2
    4
      hw6/task2/src/command.rs
  2. 10
    0
      hw6/task2/src/main.rs
  3. 5
    12
      hw6/task2/src/shell.rs

+ 2
- 4
hw6/task2/src/command.rs ファイルの表示

4
     Cd(Option<OsString>),
4
     Cd(Option<OsString>),
5
 }
5
 }
6
 
6
 
7
-impl Command {
8
-}
7
+impl Command {}
9
 
8
 
10
 impl FromStr for Command {
9
 impl FromStr for Command {
11
-    fn from_str(s: &str) -> Result<Self, Self::Err> {
12
-    }
10
+    fn from_str(s: &str) -> Result<Self, Self::Err> {}
13
 }
11
 }

+ 10
- 0
hw6/task2/src/main.rs ファイルの表示

1
+use std::process;
2
+mod shell;
3
+
4
+fn main() {
5
+    let mut s = Shell::new(..);
6
+    match s.start() {
7
+        Ok(_) => process::exit(0),
8
+        Err(_) => process::exit(1),
9
+    }
10
+}

+ 5
- 12
hw6/task2/src/shell.rs ファイルの表示

1
 use std::io;
1
 use std::io;
2
 use std::io::prelude::*;
2
 use std::io::prelude::*;
3
+use command;
3
 
4
 
4
 struct Shell<R, W> {
5
 struct Shell<R, W> {
5
     pub reader: R,
6
     pub reader: R,
20
     }
21
     }
21
     /// Initializes the Shell Loop
22
     /// Initializes the Shell Loop
22
     pub fn start() -> Result<Self, &str> {
23
     pub fn start() -> Result<Self, &str> {
24
+        shell_loop();
23
     }
25
     }
24
     /// Waits for user inputs.
26
     /// Waits for user inputs.
25
     fn shell_loop() -> Result {
27
     fn shell_loop() -> Result {
28
+        loop {
29
+        }
26
     }
30
     }
27
     /// Prints the shell prompt.
31
     /// Prints the shell prompt.
28
     fn prompt() -> Result<Option, &str> {
32
     fn prompt() -> Result<Option, &str> {
34
 
38
 
35
 impl BufRead for Shell<R, W> {
39
 impl BufRead for Shell<R, W> {
36
     fn fill_buf(&mut self) -> Result<&[u8]> {
40
     fn fill_buf(&mut self) -> Result<&[u8]> {
37
-        let buf = match stdin.fill_buf() {
38
-            Ok(res) => res,
39
-            Err(e) => return Err(e),
40
-        }
41
-        buf.unwrap()
41
+        stdin.fill_buf()
42
     }
42
     }
43
     fn consume(&mut self, amt: usize) {
43
     fn consume(&mut self, amt: usize) {
44
     }
44
     }
50
     fn flush(&mut self) -> Result<()> {
50
     fn flush(&mut self) -> Result<()> {
51
     }
51
     }
52
 }
52
 }
53
-
54
-
55
-let mut s = Shell::new();
56
-    match s.start() {
57
-        Ok(_) => process::exit(0),
58
-        Err(_) => process::exit(1),
59
-    }

読み込み中…
キャンセル
保存