Skip to content

Commit 9912522

Browse files
committed
added day 5
1 parent bb242fa commit 9912522

File tree

15 files changed

+177
-3
lines changed

15 files changed

+177
-3
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ This repository is for code related to the guide at: https://vino.dev/blog/node-
66

77
### Day 4
88

9-
```
10-
cargo run -p day-4-hello-world
11-
```
9+
- `cargo run -p day-4-hello-world`
10+
- `cargo run -p day-4-strings-wtf-1` - intentionally does not compile.
11+
- `cargo run -p day-4-strings-wtf-2` - intentionally does not compile.
12+
13+
### Day 5
14+
15+
Reassigning:
16+
17+
- JS: `node javascript/day-5/let-vs-const/reassigning.js`
18+
- Rust: `cargo run -p day-5-let-vs-const --bin reassigning`
19+
- `cargo run -p day-5-let-vs-const --bin reassigning-wrong-type` - intentionally does not compile
20+
21+
Borrowing:
22+
23+
- `cargo run -p day-5-borrowing --bin borrow`
24+
- `cargo run -p day-5-borrowing --bin mutable-borrow` - intentionally does not compile

crates/day-5/borrowing/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "day-5-borrowing"
3+
version = "0.0.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
10+
[[bin]]
11+
name = "borrow"
12+
path = "./src/borrow.rs"
13+
14+
[[bin]]
15+
name = "mutable-borrow"
16+
path = "./src/mutable-borrow.rs"

crates/day-5/borrowing/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Test README
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::{collections::HashMap, fs::read_to_string};
2+
3+
fn main() {
4+
let source = read_to_string("./README.md").unwrap();
5+
let mut files = HashMap::new();
6+
files.insert("README", source.clone());
7+
files.insert("README2", source);
8+
9+
let files_ref = &files;
10+
let files_ref2 = &files;
11+
12+
print_borrowed_map(files_ref);
13+
print_borrowed_map(files_ref2);
14+
}
15+
16+
fn print_borrowed_map(map: &HashMap<&str, String>) {
17+
println!("{:?}", map)
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::{collections::HashMap, fs::read_to_string};
2+
3+
fn main() {
4+
let source = read_to_string("./README.md").unwrap();
5+
let mut files = HashMap::new();
6+
files.insert("README", source.clone());
7+
files.insert("README2", source);
8+
9+
let files_ref = &mut files;
10+
let files_ref2 = &mut files;
11+
12+
needs_mutable_ref(files_ref);
13+
needs_mutable_ref(files_ref2);
14+
}
15+
16+
fn needs_mutable_ref(map: &mut HashMap<&str, String>) {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "day-5-let-vs-const"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
10+
11+
[[bin]]
12+
name = "reassigning"
13+
path = "./src/reassigning.rs"
14+
15+
[[bin]]
16+
name = "reassigning-wrong-type"
17+
path = "./src/reassigning-wrong-type.rs"
18+
19+
[[bin]]
20+
name = "reassigning-rebind"
21+
path = "./src/reassigning-rebind.rs"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
let myvar = 1;
3+
println!("{}", myvar);
4+
let myvar = "3";
5+
println!("{}", myvar);
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
let mut mutable = 1;
3+
println!("{}", mutable);
4+
mutable = "3";
5+
println!("{}", mutable);
6+
}

0 commit comments

Comments
 (0)