From 7fdb9249afe07c75ad8bea568195a3a8d979d73a Mon Sep 17 00:00:00 2001 From: garhve Date: Fri, 30 Dec 2022 13:47:02 +0800 Subject: finish chapter 8 --- .../chapter-8-common-collections/vector/Cargo.toml | 8 ++++++++ .../chapter-8-common-collections/vector/src/main.rs | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 rust/theBook/chapter-8-common-collections/vector/Cargo.toml create mode 100644 rust/theBook/chapter-8-common-collections/vector/src/main.rs (limited to 'rust/theBook/chapter-8-common-collections/vector') diff --git a/rust/theBook/chapter-8-common-collections/vector/Cargo.toml b/rust/theBook/chapter-8-common-collections/vector/Cargo.toml new file mode 100644 index 0000000..07892cc --- /dev/null +++ b/rust/theBook/chapter-8-common-collections/vector/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "vector" +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/rust/theBook/chapter-8-common-collections/vector/src/main.rs b/rust/theBook/chapter-8-common-collections/vector/src/main.rs new file mode 100644 index 0000000..96bd094 --- /dev/null +++ b/rust/theBook/chapter-8-common-collections/vector/src/main.rs @@ -0,0 +1,20 @@ +fn main() { + let mut v = vec![1,2,3,4,5]; + + let op: &i32 = &v[2]; + println!("The third element is {op}"); + + let op: Option<&i32> = v.get(2); + match op { + Some(i) => println!("this is {i}"), + None => println!("this isn't"), + } + + v.push(6); + + for i in &mut v { + *i += 50; + println!("{i}"); + } + +} -- cgit v1.2.3-70-g09d2