From: Martin Pitt Date: Mon, 23 Aug 2021 11:18:15 +0000 (+0200) Subject: Split into functions X-Git-Url: https://piware.de/gitweb/?p=learn-rust.git;a=commitdiff_plain;h=98ca13fb871858f407a9b2682a4e439d0557a4f7;ds=sidebyside Split into functions --- diff --git a/src/main.rs b/src/main.rs index ff65a06..e61306a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(); +}