]> piware.de Git - learn-rust.git/blobdiff - src/main.rs
Split into functions
[learn-rust.git] / src / main.rs
index ff65a0611a6e7b40a0a86501a239ab657cc4156a..e61306ac95077cf475e0b60fd11d573531a09e2d 100644 (file)
@@ -4,8 +4,7 @@ use std::collections::HashMap;
 
 use word_utils::{first_word, second_word};
 
-fn main() {
-    // strings and functions
+fn test_strings() {
     let s = String::from("Hello world");
     println!("first word: '{}'", first_word(&s));
     println!("second word: '{}'", second_word(&s).unwrap());
@@ -17,8 +16,9 @@ fn main() {
         Some(w) => println!("match: second word of '{}' exists: {}", s2, w),
         None => println!("match: second word of '{}' does not exist", s2),
     }
+}
 
-    // vectors
+fn test_vectors() {
     let v1 = vec![1, 2, 3];
     println!("statically initialized vector: {:?}", v1);
 
@@ -33,8 +33,9 @@ fn main() {
     for el in &v2 {
         println!("{}", el);
     }
+}
 
-    // hash maps
+fn test_hashmaps() {
     let mut scores = HashMap::new();
     scores.insert("john", 10);
     scores.insert("mary", 20);
@@ -65,3 +66,9 @@ fn main() {
         .collect();
     println!("collect_scores after rebuilding with doubling: {:?}", collect_scores);
 }
+
+fn main() {
+    test_strings();
+    test_vectors();
+    test_hashmaps();
+}