summaryrefslogtreecommitdiff
path: root/rust/theBook/chapter-8-common-collections/vector/src
diff options
context:
space:
mode:
authorgarhve <git@garhve.com>2022-12-30 13:47:02 +0800
committergarhve <git@garhve.com>2022-12-30 13:47:02 +0800
commit7fdb9249afe07c75ad8bea568195a3a8d979d73a (patch)
tree7360a15557b767071917204a1868b5672372dcb5 /rust/theBook/chapter-8-common-collections/vector/src
parent8a8302fa5d94425c01b358de57c071d32af6b7ed (diff)
finish chapter 8
Diffstat (limited to 'rust/theBook/chapter-8-common-collections/vector/src')
-rw-r--r--rust/theBook/chapter-8-common-collections/vector/src/main.rs20
1 files changed, 20 insertions, 0 deletions
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}");
+ }
+
+}