Browse Source

Added Comments/Documentation in all .rs files

Lorenz Bung 7 years ago
parent
commit
87c2d173e1
3 changed files with 19 additions and 5 deletions
  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 View File

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

+ 14
- 5
hw10/task1/srv-commands/src/lib.rs View File

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
 pub fn parse(message: &str) -> Result<Command, ParseError> {
6
 pub fn parse(message: &str) -> Result<Command, ParseError> {
2
     let m: String = String::from(message.trim_right());
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
         Some(x) => {
10
         Some(x) => {
6
-            let mut str = x.split_whitespace();
11
+            let mut str = x.split_whitespace(); // Teile an Leerzeichen
7
             match str.next() {
12
             match str.next() {
8
                 Some("STAGE") => {
13
                 Some("STAGE") => {
9
-                    let msg = m[6..].trim_left();
14
+                    let msg = m[6..].trim_left(); // msg = Alles außer STAGE
10
                     Ok(Command::Stage(msg.to_string()))
15
                     Ok(Command::Stage(msg.to_string()))
11
                 }
16
                 }
12
                 Some("CONTROL") => {
17
                 Some("CONTROL") => {
13
-                    let cmd = m[8..].trim_left();
18
+                    let cmd = m[8..].trim_left(); // cmd = Alles außer CONTROL
14
                     Ok(Command::Control(cmd.to_string()))
19
                     Ok(Command::Control(cmd.to_string()))
15
                 }
20
                 }
16
                 Some("RETRIEVE") => Ok(Command::Retrieve),
21
                 Some("RETRIEVE") => Ok(Command::Retrieve),
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
 #[derive(Debug, PartialEq)]
32
 #[derive(Debug, PartialEq)]
26
 pub enum Command {
33
 pub enum Command {
27
     Stage(String),
34
     Stage(String),
29
     Retrieve,
36
     Retrieve,
30
 }
37
 }
31
 
38
 
39
+/// Datentyp zur Fehlerbehandlung. ErrorType gibt den Fehlertyp an.
32
 #[derive(Debug, PartialEq)]
40
 #[derive(Debug, PartialEq)]
33
 pub struct ParseError(pub ErrorType);
41
 pub struct ParseError(pub ErrorType);
34
 
42
 
43
+/// Datentyp zur Beschreibung der in parse() auftretenden Fehlertypen.
35
 #[derive(Debug, PartialEq)]
44
 #[derive(Debug, PartialEq)]
36
 pub enum ErrorType {
45
 pub enum ErrorType {
37
     UnknownCommand,
46
     UnknownCommand,

+ 2
- 0
hw10/task1/srv-config/src/lib.rs View File

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

Loading…
Cancel
Save