瀏覽代碼

Added Comments/Documentation in all .rs files

Lorenz Bung 7 年之前
父節點
當前提交
87c2d173e1
共有 3 個檔案被更改,包括 19 行新增5 行删除
  1. 3
    0
      hw10/task1/src/main.rs
  2. 14
    5
      hw10/task1/srv-commands/src/lib.rs
  3. 2
    0
      hw10/task1/srv-config/src/lib.rs

+ 3
- 0
hw10/task1/src/main.rs 查看文件

@@ -8,6 +8,7 @@ use srv_commands::Command;
8 8
 use srv_config::Config;
9 9
 use HashServerError::Parse;
10 10
 
11
+/// Datentyp für die beim Server auftretenden Fehlertypen.
11 12
 #[derive(Debug)]
12 13
 pub enum HashServerError {
13 14
     Parse(srv_commands::ParseError),
@@ -26,6 +27,7 @@ impl From<srv_commands::ParseError> for HashServerError {
26 27
     }
27 28
 }
28 29
 
30
+/// Funktion zum Abarbeiten eines Clients.
29 31
 fn handle_client(stream: &TcpStream, orders: &mut VecDeque<String>, v: bool) {
30 32
     let mut reader = BufReader::new(stream);
31 33
     let mut writer = BufWriter::new(stream);
@@ -75,6 +77,7 @@ fn handle_client(stream: &TcpStream, orders: &mut VecDeque<String>, v: bool) {
75 77
     }
76 78
 }
77 79
 
80
+/// Hauptfunktion, die beim Starten des Servers ausgeführt wird.
78 81
 pub fn main() {
79 82
 
80 83
     let c = Config::load();

+ 14
- 5
hw10/task1/srv-commands/src/lib.rs 查看文件

@@ -1,16 +1,21 @@
1
+/// Diese Funktion parst die übergebene Nachricht und erkennt die Befehle
2
+/// "STAGE", "CONTROL" und "RETRIEVE". Bei den ersten beiden wird der nachfolgende
3
+/// String als Nachricht zurückgegeben; der Eingabestring wird bis zum ersten
4
+/// Zeilenumbruch gelesen. Wird kein Befehl erkannt, wird ein entsprechender
5
+/// Fehler zurückgegeben.
1 6
 pub fn parse(message: &str) -> Result<Command, ParseError> {
2 7
     let m: String = String::from(message.trim_right());
3
-    let mut line = m.lines();
4
-    match line.next() {
8
+    let mut line = m.lines(); // Eingabestring an Zeilenende abtrennen
9
+    match line.next() { // Betrachte nur die erste Zeile
5 10
         Some(x) => {
6
-            let mut str = x.split_whitespace();
11
+            let mut str = x.split_whitespace(); // Teile an Leerzeichen
7 12
             match str.next() {
8 13
                 Some("STAGE") => {
9
-                    let msg = m[6..].trim_left();
14
+                    let msg = m[6..].trim_left(); // msg = Alles außer STAGE
10 15
                     Ok(Command::Stage(msg.to_string()))
11 16
                 }
12 17
                 Some("CONTROL") => {
13
-                    let cmd = m[8..].trim_left();
18
+                    let cmd = m[8..].trim_left(); // cmd = Alles außer CONTROL
14 19
                     Ok(Command::Control(cmd.to_string()))
15 20
                 }
16 21
                 Some("RETRIEVE") => Ok(Command::Retrieve),
@@ -22,6 +27,8 @@ pub fn parse(message: &str) -> Result<Command, ParseError> {
22 27
     }
23 28
 }
24 29
 
30
+/// Datentyp zur Beschreibung der durch parse() erkannten Befehle.
31
+/// Stage und Control liefern die Nachricht als String mit.
25 32
 #[derive(Debug, PartialEq)]
26 33
 pub enum Command {
27 34
     Stage(String),
@@ -29,9 +36,11 @@ pub enum Command {
29 36
     Retrieve,
30 37
 }
31 38
 
39
+/// Datentyp zur Fehlerbehandlung. ErrorType gibt den Fehlertyp an.
32 40
 #[derive(Debug, PartialEq)]
33 41
 pub struct ParseError(pub ErrorType);
34 42
 
43
+/// Datentyp zur Beschreibung der in parse() auftretenden Fehlertypen.
35 44
 #[derive(Debug, PartialEq)]
36 45
 pub enum ErrorType {
37 46
     UnknownCommand,

+ 2
- 0
hw10/task1/srv-config/src/lib.rs 查看文件

@@ -3,6 +3,7 @@ extern crate clap;
3 3
 
4 4
 use clap::App;
5 5
 
6
+/// Datentyp zur Beschreibung der Konfiguration des Servers.
6 7
 pub struct Config {
7 8
     pub address: String,
8 9
     pub port: String,
@@ -11,6 +12,7 @@ pub struct Config {
11 12
 }
12 13
 
13 14
 impl Config {
15
+    /// Funktion zum Lesen der Konfigurationsdatei des Servers.
14 16
     pub fn load() -> Self {
15 17
         let yaml = load_yaml!("cli.yml");
16 18
         let matches = App::from_yaml(yaml).get_matches();

Loading…
取消
儲存