Skip to content

Commit

Permalink
feat: collections chapter
Browse files Browse the repository at this point in the history
Signed-off-by: Fredrik Klingenberg <[email protected]>
  • Loading branch information
fredrkl committed Mar 27, 2024
1 parent 742eef8 commit 618e40d
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions projects/collections/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ fn main() {

let _v: Vec<i32> = Vec::new();
let _w = vec![1, 2, 3];
let _something: Vec<bool> = Vec::new();

let mut v = Vec::new();
v.push(5);
Expand All @@ -17,8 +18,8 @@ fn main() {

let third = v.get(2); // The reson why this is option is because it might not exist, the index might be out of bounds
match third {
Some(third) => println!("The third element is {}", third),
None => println!("There is no third element"),
Some(third) => println!("The third element is {}", third),
None => println!("There is no third element"),
}

for i in &v {
Expand All @@ -27,11 +28,7 @@ fn main() {

let mut v = vec![100, 32, 57];
for i in &mut v {
*i += 50; // Dereference i to get the value it refers to, then add 50 to that value
}

for i in &v {
println!("{i}");
*i += 50;
}

enum SpreadsheetCell {
Expand All @@ -49,14 +46,12 @@ fn main() {
}
}

let s = String::new();
let _reference = &s;
let data = "initial contents";
let mut _s = data.to_string();
let s2 = "initial contents";
_s.push_str(s2);
println!("{s2}");

let mut _s = data.to_string();
_s.push_str(s2);
println!("{_s}");
let s1 = String::from("tic");
let s2 = String::from("tac");
let s3 = String::from("toe");
Expand Down

0 comments on commit 618e40d

Please sign in to comment.