From 1e7e663d489ff7707bda7240a1bd931b0a2888ec Mon Sep 17 00:00:00 2001 From: sgoudham Date: Fri, 14 Jan 2022 01:53:46 +0000 Subject: [PATCH] Add vectors --- vectors/Cargo.toml | 8 ++++++++ vectors/src/main.rs | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 vectors/Cargo.toml create mode 100644 vectors/src/main.rs diff --git a/vectors/Cargo.toml b/vectors/Cargo.toml new file mode 100644 index 0000000..b08136f --- /dev/null +++ b/vectors/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "vectors" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/vectors/src/main.rs b/vectors/src/main.rs new file mode 100644 index 0000000..a641a24 --- /dev/null +++ b/vectors/src/main.rs @@ -0,0 +1,16 @@ +fn main() { + // Create Vector + let v1: Vec = Vec::new(); + + // Create Vector with initial elements + let v2 = vec![1, 2, 3]; + + // Mutate Vector + let mut v3 = vec![1, 2, 3]; + v3.push(4); + + // Iterating over immutable references of v3 + for i in &v3 { + print!("{}", i); + } +}