From 1311d5a93dd0f7e31b3c0f88fad82c5b8d8ef3e8 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Sun, 22 Aug 2021 16:03:34 +0200 Subject: [PATCH] Vector iteration --- src/main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main.rs b/src/main.rs index 058f858..396d3f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,4 +14,19 @@ fn main() { Some(w) => println!("match: second word of '{}' exists: {}", s2, w), None => println!("match: second word of '{}' does not exist", s2), } + + let v1 = vec![1, 2, 3]; + println!("statically initialized vector: {:?}", v1); + + let mut v2: Vec = Vec::new(); + v2.push("Hello".to_string()); + v2.push(String::from("world")); + println!("dynamically built vector: {:?}", v2); + println!("first element: {}", v2[0]); + for el in &mut v2 { + *el += "xx"; + } + for el in &v2 { + println!("{}", el); + } } -- 2.39.5